gpt4 book ai didi

android NotificationCompat.Builder 未定义

转载 作者:太空狗 更新时间:2023-10-29 12:47:02 26 4
gpt4 key购买 nike

当我尝试将我的通知代码设置为按钮时这部分总是给我错误

NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(this)

[[构造函数 NotificationCompat.Builder(new View.OnClickListener(){}) 未定义]]

我该如何解决这个问题???

Button button9= (Button) findViewById(R.id.button9);
button9.setOnClickListener(new View.OnClickListener(){
public void onClick(View arg0) {


///////////My Notification//////////////////////////
NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("I'm astm loooooooool")
.setContentText("Hello baby to my world!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, MainActivity.class);

// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself) (ResultActivity)
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int mId = 0;
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());
///////////End Notification//////////////////////////
}
});

最佳答案

感谢大家帮助我 [[ 没有人给我任何答案 looooooool ]]

我自己得到答案只需将 NotificationCompat.Builder 定义为 Final,它运行良好

^__^

        ///////// my Nine button (set Notification) //////////
final NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("I'm astm loooooooool")
.setContentText("Hello baby to my world!");
Button button9= (Button) findViewById(R.id.button9);
final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
button9.setOnClickListener(new View.OnClickListener(){
public void onClick(View arg0) {

///////////My Notification//////////////////////////
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent();

// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
// Adds the back stack for the Intent (but not the Intent itself) (ResultActivity)
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int mId = 0;
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());
///////////End Notification//////////////////////////

}
});

关于android NotificationCompat.Builder 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17187021/

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