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