0

我编写了一个简单的倒数计时器应用程序,并使用下面的代码在倒计时完成时打开屏幕、振动并播放警报声:

Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
RingTone r = RingtoneManager.getRingtone(mContext, notification);
WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK|PowerManager.ACQUIRE_CAUSES_WAKEUP, "Countdown Timer");

wl.acquire(1000);

v.vibrate(pattern, -1);     
r.play();

虽然这在手机充电时工作正常,但当我断开充电器时,唤醒锁不会打开屏幕,当我使用电源按钮手动打开屏幕时,我只会收到振动和警报。

当我在不同的设备上测试它时,它似乎工作正常。

有什么想法吗?

4

2 回答 2

0

我正在使用它,它工作正常

// set up wakelock
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
WakeLock wakelock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");
wakelock.acquire();
于 2012-02-27T20:35:27.277 回答
0

您的代码wl.acquire(1000);将在 1 秒后释放唤醒锁。试试这个代码:

wl.acquire();
v.vibrate(pattern, -1);     
r.play();
w1.release();
于 2012-02-27T20:24:35.667 回答