1
I have the following code:
private Notification ongoingNotification() {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(getApplicationContext(), PlayerUI.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
String title = "meuplayer";
String msg = "Tocando. Clique para abrir.";
if (currentStreamBeingPlayed != null) {
msg = currentStreamBeingPlayed.getTitle();
}
PendingIntent previousSongPendingIntent = createPendingIntent(PlayerService.PREVIOUS_SONG);
PendingIntent pausePendingIntent = createPendingIntent(PlayerService.PAUSE);
PendingIntent nextSongPendingIntent = createPendingIntent(PlayerService.NEXT_SONG);
PendingIntent playPendingIntent = createPendingIntent(PlayerService.PLAY);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.mipmap.ic_notification)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg)
.addAction(R.mipmap.ic_prev, "", previousSongPendingIntent);
if (!mediaPlayer.isPlaying()) {
mBuilder.addAction(R.mipmap.ic_play, "", playPendingIntent);
} else {
mBuilder.addAction(R.mipmap.ic_pause, "", pausePendingIntent);
}
mBuilder.addAction(R.mipmap.ic_next, "", nextSongPendingIntent)
.setOngoing(true);
if (currentStreamBeingPlayed != null && currentStreamBeingPlayed.getPicture() != null) {
try {
URL urlPicture = new URL(currentStreamBeingPlayed.getPicture());
Bitmap largeIcon = ImageHandler.decodeURLstreamToBitmap(urlPicture, getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width), getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height));
mBuilder.setLargeIcon(largeIcon);
} catch (MalformedURLException e) {
} catch (Resources.NotFoundException e) {
} catch (IOException e) {
}
}
mBuilder.setContentIntent(contentIntent);
return mBuilder.build();
}
How can I make the image within the notification update along with the song (whether paused or in play)? because it is not giving an upgrade as the music runs
I did this but either he gets stuck yet or he just doesn’t open the notification anymore
– Aleff Matos
Not giving exception? I have similar codes working like this Alef, the difference is that I leave the Notificationmanager out of the method
– Jhonatas
but how do I make the Notificationmanager out, so it will give "java.lang.Nullpointerexception: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null Object Reference"
– Aleff Matos
and then where can I put mNotificationManager.notify(seu_id, ongoingNotification())?
– Aleff Matos