Android Lollipop中的另一个通知被取消

时间:2015-10-28 20:28:47

标签: android notifications sms android-5.0-lollipop persistent

我在Service中创建了一个通知(从BroadcastReceiver启动):

this.notification = new NotificationCompat.Builder(getApplicationContext())
    .setContentTitle("Foo")
    .setContentText("Bar")
    .setSmallIcon(R.drawable.logo)
    .setContentIntent(pIntent)
    .build();
this.initializeNotificationSound(volumne, Uri.parse(melody));
this.initializeNotificationVibration();

notification.flags = Notification.FLAG_INSISTENT;
this.notificationManager.cancelAll();
this.notificationManager.notify(0, notification);

收到特定短信时会设置此通知。我想创建一个通知,它将播放定义的旋律,不会被标准的短信通知中断。

此功能非常有用,但在棒棒糖中,会出现以下情况:

  1. 收到短信
  2. 我的通知已启动
  3. 一段时间后,通知声音停止并播放默认短信铃声
  4. 仅当铃声模式静音时才会发生这种情况。否则,它会按预期工作,因为cancelAll()方法会中断SMS通知。

    提前感谢您的回复。

1 个答案:

答案 0 :(得分:0)

你不能改变它。如果您注意到,当同时创建多个通知时,即使是来自单一应用程序(例如Facebook),它们所发出的声音也会同时播放。这与android系统本身的通知管理有关。也许您遇到的问题是由于对特定Android系统版本(API级别)进行了一些代码更改,可能是cancelAll()方法。一种解决方案是找到用于检查当前系统版本的适当代码行。例如:

if(System_version <= lollipop) {
//code works fine. Keep as it is
}
else{
//find the appropriate method and call it here.
}