block the "erase" of the screen by time of inactivity

9

My application works as a guide for a professional illuminator, it works passively (responds via Bluetooth to user commands in your working tool) or offline where the user can operate it manually in parallel with their tool , the issue is that on both occasions the user would stay a long time without interacting with the application, however reading your data constantly, it is essential that the screen does not turn off or dim, I know that the user may well set this manually, but I wanted from within the application.

I searched on Google but only bullshit, talking about app to save battery and etc., the problem is that the keywords are the same as several questions of lay users.

I searched the site but found nothing here.

I searched Google Developers, but because I did not know English very well, and because their explanation was not very intuitive, I did not get constructive results. Can someone help me?

    
asked by anonymous 24.10.2014 / 18:39

2 answers

7

Try to put this in onCreate of your Activity

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

Or within your layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">

If you want to read more about:

link

I hope it helps!

    
24.10.2014 / 18:48
2

I think you'll need this WakeLock , but it seems that the answer above also resolves the doubt do the test with both on different devices.

You also have the option to partially do this WakeLock Partial

//ONCREATE
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, TAG);
wl.acquire(); //informa para nao desligar a tela

//quando sair da atividade ou do apk 
wl.release(); //informa que já esta liberado para desligar
    
24.10.2014 / 18:59