【问题标题】:Notification being cancelled by another one in Android LollipopAndroid Lollipop 中的另一个通知正在取消通知
【发布时间】:2015-10-28 20:28:47
【问题描述】:

我以这种方式在 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);

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

这个功能效果很好,但是在棒棒糖中,会发生以下情况:

  1. 收到短信
  2. 我的通知已启动
  3. 一段时间后,通知声音停止并播放默认短信铃声

仅当铃声模式为静音时才会发生这种情况。否则,它会按预期工作,因为 cancelAll() 方法会中断 SMS 通知。

提前感谢您的回复。

【问题讨论】:

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


    【解决方案1】:

    你无法改变这一点。如果您注意到,当同时创建多个通知时,即使是来自单个应用程序(例如 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.
    }
    

    【讨论】:

    • 我将不胜感激以下之一: 1:仅在我取消我的之后从“堆栈”运行另一个通知。 2. 在另一个(打断我的)完成后,再次启动我的通知。
    • 1:尝试搜索documentation,并找到适合您使用的标志。 2:尝试 1 并告诉我它是否有效
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    • 2015-05-01
    • 2015-03-23
    • 1970-01-01
    相关资源
    最近更新 更多