【发布时间】:2016-11-11 14:08:44
【问题描述】:
一直在尝试找到一种创建持久提醒通知的方法,就像接听电话或环聊电话一样。这些是否仅限于 Google/系统应用?
我试过了:
- 在提示通知被删除之前更新通知。
- 将正在进行的标志设置为真。
- 将自动取消设置为 false
似乎无法在任何地方找到此操作。
【问题讨论】:
标签: java android android-5.0-lollipop android-notifications heads-up-notifications
一直在尝试找到一种创建持久提醒通知的方法,就像接听电话或环聊电话一样。这些是否仅限于 Google/系统应用?
我试过了:
似乎无法在任何地方找到此操作。
【问题讨论】:
标签: java android android-5.0-lollipop android-notifications heads-up-notifications
它对我有用:
【讨论】:
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。
【讨论】:
只需将setOngoing 添加为true。 .setOngoing(true);,这就是您制作通知(抬头)的方式,显示时间更长,而且通知面板中现在没有不可滑动的通知。
【讨论】: