简体   繁体   中英

How to Keep Screen On in Android Tv

I am developing two applications for android tv.

  1. The first is a launcher to customize the startup interface a bit.

  2. The second is a video player by HLS or Streaming by https.

They independently work great.

Then in the launcher I have an attempt that starts the video player after 1 minute. The problem is that after 20 minutes the Smart TV enters this suspension or low-power mode.

I already tried keepOnScreen in the layout, I tried WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON without good results.

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.abc"); startActivity(launchIntent );

Note: When I open the multimedia application of the Smart TV and return to the player, the Smart TV does not turn off.

If you are using VideoSupportFragment then you can access to SurfaceView and do this in your onViewCreated(..) callback to keep the screen on:

getSurfaceView().setKeepScreenOn(true);

same in Kotlin:

surfaceView.keepScreenOn = true

OR, in your XML layout, add this to your View :

android:keepScreenOn="true"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM