Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android disable display off while charging

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?

like image 560
skayred Avatar asked Nov 05 '22 11:11

skayred


1 Answers

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

like image 80
skayred Avatar answered Nov 11 '22 11:11

skayred