如何连续停止和播放通知?

时间:2013-03-08 05:13:40

标签: android notifications notificationmanager

我想实现这个目标:

  • 当闹钟响起时,通知声音应该连续播放,直到用户拖动通知栏。
  • 当我向下拖动通知栏时,声音应停止播放。

2 个答案:

答案 0 :(得分:5)

在通知中,几乎没有用于自动停止通知的标志,你必须使用它们。

  1. Notification.DEFAULT_SOUND:用于播放声音。
  2. 2.Notification.FLAG_INSISTENT:此标志会让您的声音持续响起,直到您对通知进行了少量操作,即拖动栏或单击栏。

    3.Notification.FLAG_AUTO_CANCEL:此标志用于在您看到通知后自动取消通知

答案 1 :(得分:2)

why the nastiness with reflection?

因为它不是Android SDK的一部分。只有对创建不可靠应用程序感兴趣的人才会尝试与Android源代码本身之外的StatusBarManager进行交互。由于核心Android团队和设备制造商欢迎随时随地更改SDK之外的任何内容。

Why can't I find a reference to the StatusBarManager class directly?

因为它不是Android SDK的一部分。由于种种原因,Android框架中有很多很好的类和方法都标有@hide注释:不愿承诺无限期地支持API,“默默无闻的安全”等等。

Why is there not a constant in the Context class for the "statusbar" service?

因为它不是Android SDK的一部分。当然欢迎您向AOSP提供补丁,以便将StatusBarManager“提升”到与其他系统服务相同的状态(例如,LocationManager,NotificationManager)。如果在〜2007年创建SDK后,StatusBarManager情况仅仅是疏忽,那么您的补丁可能会被接受,您将在即将推出的Android版本中看到更改。

Why can't I find a reference to the StatusBarManager class directly?