|
1.Screen.sleepTimeout = SleepTimeout.NeverSleep; 并不是百分百有效
2.
public static AndroidJavaObject Activity
{
get
{
AndroidJavaClass jcPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
return jcPlayer.GetStatic<AndroidJavaObject>(&#34;currentActivity&#34;);
}
}
const int FLAG_KEEP_SCREEN_ON = 128;
public static void KeepScreenOn()
{
Debug.Log(&#34;Click KeepscreenOn&#34;);
try
{
Activity.Call(&#34;runOnUiThread&#34;, new AndroidJavaRunnable(() => {
//需要在UI线程中调用
Activity.Call<AndroidJavaObject>(&#34;getWindow&#34;).Call(&#34;addFlags&#34;, FLAG_KEEP_SCREEN_ON);
}));
}
catch (Exception e)
{
Debug.LogError(e.Message);
}
}
可以配合在AndroidManifest 中添加 <uses-permission android:name=&#34;android.permission.WAKE_LOCK&#34;/> 一起使用
3.AndroidManifest主Activity 添加Them配置 valuse下添加syles.xml文件
<activity
android:name=&#34;com.qk.unity.QuickUnityPlayerProxyActivity&#34;
android:configChanges=&#34;fontScale|orientation|keyboardHidden|locale|navigation|screenSize|uiMode&#34;
android:theme = &#34;@style/MapAutoFullScreenTheme&#34;
android:screenOrientation=&#34;portrait&#34;
tools:replace=&#34;android:configChanges,android:screenOrientation,android:theme&#34;
android:exported=&#34;true&#34;>
<intent-filter>
<action android:name=&#34;android.intent.action.MAIN&#34; />
<category android:name=&#34;android.intent.category.LAUNCHER&#34; />
</intent-filter>
<meta-data
android:name=&#34;unityplayer.UnityActivity&#34;
android:value=&#34;true&#34; />
</activity>
styles.xml 文件
<resources>
<style name=&#34;MapAutoFullScreenTheme&#34; >
<item name=&#34;android:windowNoTitle&#34;>true</item>
<item name=&#34;android:windowActionBar&#34;>false</item>
<item name=&#34;android:windowFullscreen&#34;>true</item>
<item name=&#34;android:windowContentOverlay&#34;>@null</item>
<item name=&#34;android:keepScreenOn&#34;>true</item>
</style>
</resources>4.第三种方法无法解决刘海屏问题 会一直存在刘海屏 解决方法:修改style.xml 套用Unity官方布局
<resources>
<style name=&#34;MapAutoFullScreenTheme&#34; parent=&#34;BaseUnityTheme&#34;>
<item name=&#34;android:windowBackground&#34;>@android:color/black</item>
<item name=&#34;android:keepScreenOn&#34;>true</item>
</style>
<style name=&#34;BaseUnityTheme&#34; parent=&#34;android:Theme.Light.NoTitleBar.Fullscreen&#34;>
</style>
<style name=&#34;UnityThemeSelector.Translucent&#34; parent=&#34;@style/UnityThemeSelector&#34;>
<item name=&#34;android:windowIsTranslucent&#34;>true</item>
<item name=&#34;android:windowBackground&#34;>@android:color/transparent</item>
</style>
</resources>
以上基本解决息屏及适配问题,真的是不容易啊,还望点个赞或者打赏一下,感谢。 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|