gpt4 book ai didi

java - Android Alarmmanager 和通知

转载 作者:行者123 更新时间:2023-11-30 09:31:03 25 4
gpt4 key购买 nike

以下代码无效。也试试这个而不是 getapplicationcontext。我需要一个提示:

public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder nb = new NotificationCompat.Builder();
nb.setContentTitle("title");
nb.setContentText("message");
nb.setSmallIcon(R.drawable.ic_launcher);
NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
final Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
final PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
nb.setContentIntent(contentIntent);
Notification notification = nb.getNotification();
nm.notify(0, notification);
}

}

如何在点击后删除通知?

更新:我解决了一个错误。但是还有一个错误:

Screenshot

最佳答案

将 getSystemService 替换为 context.getSystemService!

关于java - Android Alarmmanager 和通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13032259/

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