Reputation: 1716
I'm trying to update a notification, But I'm not able to do it, Here's my code :
NotificationCompat.Builder nBuilder;
RemoteViews remoteView;
static NotificationManager nManager;
static int NOFIY_ID = 2;
static Bitmap bitmap2;
static boolean isExists2;
public void MakeNotification(Context context,String Name,String AlbumART) {
if(Added_RvHolders.isPlaying)
Added_RvHolders.mMediaPlayer.stop();
if(!AlbumART.equals("")) {
Uri sArtworkUri = Uri
.parse("content://media/external/audio/albumart");
Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, Long.parseLong(AlbumART));
try {
bitmap2 = MediaStore.Images.Media.getBitmap(
context.getContentResolver(), albumArtUri);
isExists2 = true;
} catch (IOException e) {
isExists2 = false;
}
} else {
isExists2 = false;
}
if(IsFirstTime) {
nBuilder = new NotificationCompat.Builder(context)
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setSmallIcon(R.mipmap.small_app_icon)
.setOngoing(true);
remoteView = new RemoteViews(context.getPackageName(), R.layout.music_notification);
}
if(isExists2)
remoteView.setImageViewBitmap(R.id.AlbumART, bitmap2);
else
remoteView.setImageViewResource(R.id.AlbumART,R.mipmap.main_app_icon);
remoteView.setTextViewText(R.id.TrackTitle,Name);
//set the button listeners
setListeners(remoteView, context);
nBuilder.setContent(remoteView);
nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nManager.notify(NOFIY_ID, nBuilder.build());
}
What's wrong :
It's not being updated when choosing another song, in the 'OnClick' method, I'm passing the new name/cover art, But it's not updating, Even though I've tried to "cancel" the notification and make it again, Still on the same info .
What i'm expecting ? :
The notification gets updated when a new song is pressed .
Upvotes: 2
Views: 1909
Reputation: 1716
Beside using the same builder, You MUST NOT put the builder as static, or the remoteview, removing static solved my problem .
Upvotes: 1