5

In my application I need to disable display power off when device is charging. There is an option in Developer Menu to disable it, so I can to send Intent for user to enable it.

Also I've found info about PowerManager and WakeLocks, but it is for Alarms, I think. And I must to handle, is device charging.

What is the better, or is there another way to do this?

skayred
  • 10,603
  • 10
  • 52
  • 94
  • See [here](http://stackoverflow.com/questions/1805895/android-battery-in-sdk) and then [BatteryManager](http://developer.android.com/reference/android/os/BatteryManager.html) – Vlad Nov 17 '11 at 06:42

2 Answers2

2

I've do this by that code:

final boolean isStayAwake = isStayAwakeEnabled(context);

if (!isStayAwake) {
    intent = new Intent(ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
}

context.startActivity(intent);

There user must check 'stay awake' option

I've used my own ACTION_APPLICATION_DEVELOPMENT_SETTINGS constant because of problems with default one, which have not "com." prefix

skayred
  • 10,603
  • 10
  • 52
  • 94
0

Perhaps you want to try FLAG_KEEP_SCREEN_ON from the WindowManager.LayoutParams

Will Tate
  • 33,439
  • 9
  • 77
  • 71