更新

时间:2016-03-10 00:04:46

标签: android notifications android-notifications

我有一个通知,显示有关我的应用中播放的歌曲的信息。一切似乎都有效,但是当我更新通知时,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());
}

你们有没有想过为什么会这样?

1 个答案:

答案 0 :(得分:0)

对不起伙计们。我从一个不再有变量的intent中回忆起一个intent.getStringExtra()。谢谢你的帮助。