我正在尝试为带有控件的音乐播放器发出通知。我成功收听了按钮单击事件,并且功能正在正确触发。我面临的唯一问题是更改这些点击事件的通知文本。这就是我正在尝试的。
这是接收器成功接收呼叫并完美地触发每一行。但我不能改变文字。我想我必须将内容视图重置为通知。如果是这样,我该怎么做?
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals("stop")) {
ABCFragment.stopSong();
Log.d("Notification","Stopping");
}else if (action.equals("play")) {
ABCFragment.togglePlayPause();
Log.d("Notification","Toggle Play/Pause");
RemoteViews contentView = new RemoteViews(context.getPackageName(),R.layout.notification_layout);
contentView.setTextViewText(R.id.songName, "SOME NEW SONG");
}else if (action.equals("next")) {
ABCFragment.playNextSong();
Log.d("Notification","Next");
}
}
解决方案 :
我更新了我的 Notification 类构造函数以传递一个额外的参数并让它工作!
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals("stop")) {
ABCFragment.stopSong();
Log.d("Notification","Stopping");
}else if (action.equals("play")) {
ABCFragment.togglePlayPause();
Log.d("Notification","Toggle Play/Pause");
new ABCNotification(context, "SOME NEW SONG");
}else if (action.equals("next")) {
ABCFragment.playNextSong();
Log.d("Notification","Next");
}
}
构造函数正在处理新传递的参数。