I have an android app which runs a foreground service and while that service is running I would like to give the user the option to keep the screen on.
I added to my settings preferences, a checkbox preference and if true, I would like to keep the screen on but have it set to off by default. It's just something my users have asked for. Currently i have the preference on but when I run the service my screen still shuts of here is what I've done
global variable
private static final String PREFS_DEVICE = "DeviceInfo";
code and if statement
SharedPreferences settings = getSharedPreferences(PREFS_DEVICE, 0);
if(settings.getBoolean("screenPref", false)) {
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
this.mWakeLock.acquire();
}
and then i added this to my manifest
<uses-permission android:name="android.permission.WAKE_LOCK" />
Is there something I'm doing wrong. Is there a different way to do this from a service or is it just not possible from a service (hope that's not the case).