0
我正在進行自定義通知,並且在接收者中意圖更改通知本身的佈局中的元素中的文本。當我更新通知時沒有任何反應。意圖正在傳遞給接收者,我檢查了日誌。使通知的活動和接收者是獨立的類。有任何想法嗎?我知道那個AppWidgetProvider對於widget的效果很好,但是在這種情況下沒有AppWidgetProvider,這是一個普通的通知。有沒有其他的方法來使RemoteView無效?如何使RemoteView失效
//Receiver.onReceive() method
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notification_layout);
//make dataString
views.setTextViewText(R.id.n_track_name, dataString);
//while searching i figured out this is something that should update notification
NotificationManager mNotificationManager = (NotificationManager)act.getSystemService(Activity.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, act.notification);
這是代碼,這使得通知在其他活動第一次:
Notification notification = new Notification(icon, "Music Player", when);
NotificationManager mNotificationManager = (NotificationManager)MusicPlayerActivity.currentActivity.getSystemService(NOTIFICATION_SERVICE);
RemoteViews contentView = new RemoteViews(act.getPackageName(), R.layout.notification_layout);
//make pending intent on button
Intent intent = new Intent(act, NotificationReceiver.class);
intent.setAction(NotificationReceiver.ACTION_NOTIFICATION_NEXT);
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(act, 0, intent, 0);
contentView.setOnClickPendingIntent(R.id.n_btnNext, actionPendingIntent);
//make other intents
//show notification
mNotificationManager.notify(1, notification);