block "erasing" the screen for downtime

Asked

Viewed 3,184 times

9

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

I searched on Google but only appears bullshit, talking app to save battery and etc, the problem is that keywords are the same of various questions of users laypeople.

I searched the site but found nothing here.

I looked at Developers from Google, but because I don’t know English very well, and because their explanation isn’t very intuitive, I didn’t get any constructive results. someone can help me?

2 answers

7


Try putting this on onCreate of his 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 would like to read more about:

https://developer.android.com/training/scheduling/wakelock.html

I hope it helps!

  • it worked out Valew guy;

  • Strange, I tested both forms, in the Android 4.4.4 API 19 only option getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); kept the screen active but solved my problem, thanks.

2

I think you’re gonna need this Wakelock, but it seems that the above answer also solves in doubt makes the test with the two in different appliances.

There is also the option to do this partially 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
  • in Galaxy note 2 worked but I will try on several devices before releasing, do not delete your answer please, when I finish performing the tests I will test your tbm!

  • does this the times the systems are customized and may vary according to the manufacturer of the appliance. If you have devices to test it’s worth it and save time :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.