2

私はカスタム通知を作成しています。インテントのレシーバーで、通知自体のレイアウトの要素のテキストを変更します。通知を更新しても何も起こりません。インテントがレシーバーに渡されています。ログを確認しました。通知を行うアクティビティと受信者は別のクラスです。何か案は?ウィジェットの 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);
4

1 に答える 1

0

誰かが同じ問題を抱えている場合、ここに解決策があります:

act.notification.contentView = views;

このコードは、Receiver コードを配置する必要があります。変更された RemoteView を開始通知に割り当てる必要があり、そうして初めて Notificationmanager が実際に古いビューを新しいビューに置き換えることができます。

于 2014-03-02T10:30:01.350 に答える