【问题标题】:Extend Lollipops "heads-up" notification duration延长棒棒糖“提醒”通知持续时间
【发布时间】:2016-11-11 14:08:44
【问题描述】:

一直在尝试找到一种创建持久提醒通知的方法,就像接听电话或环聊电话一样。这些是否仅限于 Google/系统应用?

我试过了:

  • 在提示通知被删除之前更新通知。
  • 将正在进行的标志设置为真。
  • 将自动取消设置为 false

似乎无法在任何地方找到此操作。

【问题讨论】:

    标签: java android android-5.0-lollipop android-notifications heads-up-notifications


    【解决方案1】:

    它对我有用:

    • 将正在进行的标志设置为 true
    • 设置全屏意图
    • 将优先级设置为 PRIORITY_HIGH
    • 将类别设置为 CATEGORY_CALL

    【讨论】:

    【解决方案2】:

    Heads-Up Notifications(API 级别 21):

    可能触发提醒通知的条件示例包括:

    • 用户的 Activity 处于全屏模式(应用使用 fullScreenIntent),
    • 通知具有高优先级并使用铃声或振动

    第二个案例足以让我显示单挑通知。这是一个示例代码:

    Notification notification = new NotificationCompat.Builder(this)
            .setContentTitle("Title")
            .setContentText("Message")
            .setSmallIcon(R.drawable.ic_notification)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.your_sound))
    //        .setOngoing(true)
            .build();
    
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(42, notification);
    

    每秒运行此示例代码(取决于 your_sound.mp3 持续时间...)就可以了。

    注意,您可能想在第一次播放之后播放silent.mp3。

    【讨论】:

      【解决方案3】:

      只需将setOngoing 添加为true。 .setOngoing(true);,这就是您制作通知(抬头)的方式,显示时间更长,而且通知面板中现在没有不可滑动的通知。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-08-14
        • 1970-01-01
        • 2018-07-29
        • 1970-01-01
        • 1970-01-01
        • 2014-12-15
        • 1970-01-01
        相关资源
        最近更新 更多