我正在制作自定义通知,在意图的接收者中,我更改了通知本身布局中的元素中的文本。当我更新Notification时,什么也没有发生。意图正在传递给接收者,我检查了日志。发出通知的Activity和receiver是单独的类。有什么想法吗?我知道widget的AppWidgetProvider运行得很好,但在这种情况下没有AppWidgetProvider,这是简单的通知。有没有其他方法可以使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);发布于 2014-03-02 18:30:01
如果任何人都有同样的问题,这里是解决方案:
act.notification.contentView = views;此代码必须放入接收器代码。更改的RemoteView必须分配给启动通知,只有这样Notificationmanager才能真正用新视图替换旧视图。
https://stackoverflow.com/questions/22115963
复制相似问题