首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使RemoteView无效

如何使RemoteView无效
EN

Stack Overflow用户
提问于 2014-03-01 23:00:41
回答 1查看 551关注 0票数 2

我正在制作自定义通知,在意图的接收者中,我更改了通知本身布局中的元素中的文本。当我更新Notification时,什么也没有发生。意图正在传递给接收者,我检查了日志。发出通知的Activity和receiver是单独的类。有什么想法吗?我知道widget的AppWidgetProvider运行得很好,但在这种情况下没有AppWidgetProvider,这是简单的通知。有没有其他方法可以使RemoteView无效?

代码语言:javascript
复制
//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);

这是在其他活动中第一次生成通知的代码:

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

发布于 2014-03-02 18:30:01

如果任何人都有同样的问题,这里是解决方案:

代码语言:javascript
复制
act.notification.contentView = views;

此代码必须放入接收器代码。更改的RemoteView必须分配给启动通知,只有这样Notificationmanager才能真正用新视图替换旧视图。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22115963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档