How do I keep the screen attached in later versions of the kitkat API?

2

I'm making a APP that keeps the smartphone screen always on , even when APP is minimized.

I'm using a class with extends Service to do this, in onCreate I put the code that keeps the screen always lit:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "watever");
    wl.acquire();

Android Studio gives me an alert: FULL_WAKE_LOCK is deprecated , but I could not figure out how to do it in the current way.

This code is only working right up to KitKat . In Lollipop or later, it does not show any error, but does not work.

Example app that makes the screen stay lit even with the app closed: link

    
asked by anonymous 02.01.2017 / 20:49

1 answer

2

You currently report this in the layout, either through XML or programmatically.

I would programmatically add that to onCreate:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

In xml, just insert the following in the root layout.

android:keepScreenOn="true"
    
02.01.2017 / 21:03