【发布时间】:2010-02-07 16:36:44
【问题描述】:
我正在尝试生成一个通知,该通知会在屏幕关闭(CPU 关闭)时振动手机并播放声音。根据日志消息,正在发送通知,但手机没有振动或播放声音,直到我再次打开屏幕。我尝试持有一个 2 秒的临时唤醒锁 (PowerManager.PARTIAL_WAKE_LOCK),我认为这将是播放通知的充足时间,但唉,它仍然没有。
有任何指针可以让通知可靠运行吗?我正在运行 Android 1.6 的 G1 上对此进行测试。
我正在使用的代码:
notif.vibrate = new long[] {100, 1000};
notif.defaults |= Notification.DEFAULT_SOUND;
notif.ledARGB = Color.RED;
notif.ledOnMS = 1;
notif.ledOffMS = 0;
notif.flags = Notification.FLAG_SHOW_LIGHTS;
notif.flags |= NOTIF_FLAGS; //static var
if (!screenOn) { //var which updates when screen turns off/on
mWakeLock.acquire(2000);
}
manager.notify(NOTIF_ID, notif);
【问题讨论】:
-
您是否尝试过部署到真实设备上?也许模拟器在通知唤醒方面有问题。
标签: android notifications