gpt4 book ai didi

java - getActivity 未找到 PendingIntent

转载 作者:行者123 更新时间:2023-12-02 11:55:27 27 4
gpt4 key购买 nike

我有pendingIntent的头文件

 Intent i=new Intent();
PendingIntent pi= new PendingIntent.getActivity(MainActivity.this,0,i,0);

这似乎不起作用

这是我的完整代码

package com.example.srinabh.notof;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

Button b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=findViewById(R.id.notif);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i=new Intent();
PendingIntent pi= new PendingIntent.getActivity(MainActivity.this,0,i,0);

Notification n=new Notification.Builder(MainActivity.this)
.setTicker("Ticker Title")
.setContentTitle("Content Titlle")
.setContentText("Content Text")
.setContent(pi)
.getNotification();
n.flags=Notification.FLAG_AUTO_CANCEL;
NotificationManager nm= (NotificationManager)getSystemService(NOTIFICATION_SERVICE);



}
});
}
}

最佳答案

删除新的

  PendingIntent pi= PendingIntent.getActivity(MainActivity.this,0,i,0);

来自答案:

getActivity() is a static method of the class PendingIntent and does not require an instance of PendingIntent in order to be invoked.

答案可引用here

关于java - getActivity 未找到 PendingIntent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47637119/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com