简体   繁体   English

如何在 Android 电视中保持屏幕开启

[英]How to Keep Screen On in Android Tv

I am developing two applications for android tv.我正在为 android 电视开发两个应用程序。

  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.第二个是 HLS 的视频播放器或 https 的 Streaming。

They independently work great.他们独立工作很好。

Then in the launcher I have an attempt that starts the video player after 1 minute.然后在启动器中,我尝试在 1 分钟后启动视频播放器。 The problem is that after 20 minutes the Smart TV enters this suspension or low-power mode.问题是智能电视在 20 分钟后进入这种暂停或低功耗模式。

I already tried keepOnScreen in the layout, I tried WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON without good results.我已经在布局中尝试过 keepOnScreen,我尝试了 WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON 没有很好的结果。

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.abc"); Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.abc"); startActivity(launchIntent ); 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:如果您使用的是VideoSupportFragment那么您可以访问SurfaceView并在您的onViewCreated(..)回调中执行此操作以保持屏幕开启:

getSurfaceView().setKeepScreenOn(true);

same in Kotlin:在 Kotlin 中相同:

surfaceView.keepScreenOn = true

OR, in your XML layout, add this to your View :或者,在您的 XML 布局中,将其添加到您的View

android:keepScreenOn="true"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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