开发者

Method OnSensorChanged() when screen is lock

On my Samsung Galaxy S 2 I have the known bug when OnSe开发者_JAVA百科nsorChanged() method does not call when screen is lock (http://code.google.com/p/android/issues/detail?id=3708 ). Is there any solution for this?


You solve the problem by getting a partial wake lock from the power manager which keeps the CPU from sleeping when the screen goes off.

PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock lock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SensorRead");
lock.acquire();

Make sure to release it when you are done so you don't drain the battery.

You need this permission in your manifest too:

<uses-permission android:name="android.permission.WAKE_LOCK" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜