我試圖管理一組推送通知。1.我的第一個問題是只有最后設置的通知才能接收我的智能手機。我相信它沒有創(chuàng)建新實例,但它覆蓋了唯一的實例。我該如何解決?2.我的第二個問題是我想要從應用程序中刪除一個確定通知的時間表。這是我在MovieAdapter.java 中的代碼(主要方法是getNotification、scheduleNotification和deleteNotification):通知發(fā)布者.javapackage com.example.msnma.movienotifier.notify;import android.app.Notification;import android.app.NotificationManager;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;public class NotificationPublisher extends BroadcastReceiver{ public static String NOTIFICATION_ID = "notification-id"; public static String NOTIFICATION = "notification"; public void onReceive(Context context, Intent intent) { NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = intent.getParcelableExtra(NOTIFICATION); int id = intent.getIntExtra(NOTIFICATION_ID, 0); notificationManager.notify(id, notification); }}
1 回答

慕勒3428872
TA貢獻1848條經(jīng)驗 獲得超6個贊
改變這一行
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
到
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT); //Here 0 is the intent requestcode.
確保意圖請求代碼是唯一的以區(qū)分意圖。
添加回答
舉報
0/150
提交
取消