Unity apk开机自启动一次


1.需求

unity生成AndroidApk,只能首次启动启动,且后续关闭后重启不再启动。

2.首次启动

在Manifest文件中如下设置:android:priority设置较高是为了保证在其他launcher前启动。

      <intent-filter android:priority="2000"> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> 

3.关闭后apk禁用

    public void DisableSetupWizard() { const int COMPONENT_ENABLED_STATE_DISABLED = 2; const int DONT_KILL_APP = 1; AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject currentActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity"); AndroidJavaObject pm = currentActivity.Call<AndroidJavaObject>("getPackageManager"); AndroidJavaObject component = new AndroidJavaObject("android.content.ComponentName", "包名", "类名"); pm.Call("setComponentEnabledSetting", component, COMPONENT_ENABLED_STATE_DISABLED, DONT_KILL_APP); }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM