Android lock alarm

Hello, I am trying to implement trace lock for an application.

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");

It seems to drag out on the definition PowerManagershown in the code above. What is going wrong?

+5
source share
1 answer

Do you get this power when you run the code in the emulator on the device itself?

Have you set breakpoints in eclipse to make sure the call to getSystemService () is causing the problem?

In an eclipse, when a power circuit occurs, does LogCat talk about this?

You set

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

in the manifest?

You can also try defining pm as final:

final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

Let me know if this helps ...

+7
source

All Articles