Android 更新后通知 setContentText 消失
Android Notification setContentText dissapears after update
我有一个通知显示有关我的应用中正在播放的歌曲的信息。一切似乎都正常,但是当我更新通知时,setContentText 消失了。
这是我的代码:
public void buildnotification() {
Intent notificationIntent = new Intent(getApplicationContext(), Playback.class);
notificationIntent.setAction(Constants.ACTION.MAIN_ACTION);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0,
notificationIntent, 0);
Intent previousIntent = new Intent(getApplicationContext(), MediaPlayerService.class);
previousIntent.setAction(Constants.ACTION.PREV_ACTION);
PendingIntent ppreviousIntent = PendingIntent.getService(getApplicationContext(), 0,
previousIntent, 0);
Intent playIntent = new Intent(getApplicationContext(), MediaPlayerService.class);
playIntent.setAction(Constants.ACTION.PLAY_ACTION);
PendingIntent pplayIntent = PendingIntent.getService(getApplicationContext(), 0,
playIntent, 0);
Intent nextIntent = new Intent(getApplicationContext(), MediaPlayerService.class);
nextIntent.setAction(Constants.ACTION.NEXT_ACTION);
PendingIntent pnextIntent = PendingIntent.getService(getApplicationContext(), 0,
nextIntent, 0);
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.mipmap.coloredlogo);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int notifyID = 1;
NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(this);
mNotifyBuilder.setContentTitle("Scripture Singer")
.setTicker("Scripture Singer")
.setContentText(dName)
.setStyle(new NotificationCompat.MediaStyle())
.setSmallIcon(R.mipmap.logonowords)
.setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false))
.setContentIntent(pendingIntent)
.setOngoing(true);
mNotifyBuilder.addAction(R.mipmap.ic_skip_previous_black_48dp, "Previous", ppreviousIntent);
//changes play and pause
if (mp.isPlaying()) {
mNotifyBuilder.addAction(R.mipmap.ic_pause_black_48dp, "Pause",
pplayIntent);
} else {
mNotifyBuilder.addAction(R.mipmap.ic_play_arrow_black_48dp, "Play",
pplayIntent);
}
mNotifyBuilder.addAction(R.mipmap.ic_skip_next_black_48dp, "Next", pnextIntent);
mNotificationManager.notify(notifyID, mNotifyBuilder.build());
}
你们知道为什么会发生这种情况吗?
抱歉各位。我从一个不再有变量的意图中回忆起一个 intent.getStringExtra() 。谢谢你的帮助。
我有一个通知显示有关我的应用中正在播放的歌曲的信息。一切似乎都正常,但是当我更新通知时,setContentText 消失了。
这是我的代码:
public void buildnotification() {
Intent notificationIntent = new Intent(getApplicationContext(), Playback.class);
notificationIntent.setAction(Constants.ACTION.MAIN_ACTION);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0,
notificationIntent, 0);
Intent previousIntent = new Intent(getApplicationContext(), MediaPlayerService.class);
previousIntent.setAction(Constants.ACTION.PREV_ACTION);
PendingIntent ppreviousIntent = PendingIntent.getService(getApplicationContext(), 0,
previousIntent, 0);
Intent playIntent = new Intent(getApplicationContext(), MediaPlayerService.class);
playIntent.setAction(Constants.ACTION.PLAY_ACTION);
PendingIntent pplayIntent = PendingIntent.getService(getApplicationContext(), 0,
playIntent, 0);
Intent nextIntent = new Intent(getApplicationContext(), MediaPlayerService.class);
nextIntent.setAction(Constants.ACTION.NEXT_ACTION);
PendingIntent pnextIntent = PendingIntent.getService(getApplicationContext(), 0,
nextIntent, 0);
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.mipmap.coloredlogo);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int notifyID = 1;
NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(this);
mNotifyBuilder.setContentTitle("Scripture Singer")
.setTicker("Scripture Singer")
.setContentText(dName)
.setStyle(new NotificationCompat.MediaStyle())
.setSmallIcon(R.mipmap.logonowords)
.setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false))
.setContentIntent(pendingIntent)
.setOngoing(true);
mNotifyBuilder.addAction(R.mipmap.ic_skip_previous_black_48dp, "Previous", ppreviousIntent);
//changes play and pause
if (mp.isPlaying()) {
mNotifyBuilder.addAction(R.mipmap.ic_pause_black_48dp, "Pause",
pplayIntent);
} else {
mNotifyBuilder.addAction(R.mipmap.ic_play_arrow_black_48dp, "Play",
pplayIntent);
}
mNotifyBuilder.addAction(R.mipmap.ic_skip_next_black_48dp, "Next", pnextIntent);
mNotificationManager.notify(notifyID, mNotifyBuilder.build());
}
你们知道为什么会发生这种情况吗?
抱歉各位。我从一个不再有变量的意图中回忆起一个 intent.getStringExtra() 。谢谢你的帮助。