I am trying to make a notification for a music player with controls. I successfully listen to button press events and the functions start correctly. The only problem I encountered is changing the text of the notification about these click events. Here is what I am trying.
This is a receiver that successfully accepts calls and perfectly shoots each line. But I can not change the text. I think I need to reset the contents view for notification. If so, how to do it?
@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"); } }
Decision:
I updated the constructor of the Notification class to pass additional arguments and got it working!
@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"); } }
Constructor
processes the new arguments passed.
source share