0

Possible Duplicate:
How to lock screen, android

I am trying to lock the phones screen in my code but its not working. I've spent hours going over it and trying new ways, but nothing works. I am trying to lock the screen in a service, but first i am just trying it out in an activity.

Here's my activity:

PowerManager manager;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,   "Your Tag");

    wl.acquire();

  }

}

This just doesn't do anything at all.

Note: I do have the android.permission.WAKE_LOCK permission

I've tried this method underneath also but it just does nothing, no force close or anything.

manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
manager.goToSleep(1000); // go to sleep in 1 second

I have tried this method below and it worked (in an activity):

WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 0;
getWindow().setAttributes(params);

However this method does not work in a service, so i need to find a different way?, however i just have had no luck.

Any help? would be great, thanks, jack

Community
  • 1
  • 1
Jack Trowbridge
  • 3,175
  • 9
  • 32
  • 56

0 Answers0