public void RestartAndroid()
{
if (Application.isEditor) return;
using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
const int kIntent_FLAG_ACTIVITY_CLEAR_TASK = 0x00008000;
const int kIntent_FLAG_ACTIVITY_NEW_TASK = 0x10000000;
var currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
var pm = currentActivity.Call<AndroidJavaObject>("getPackageManager");
var intent = pm.Call<AndroidJavaObject>("getLaunchIntentForPackage", Application.identifier);
intent.Call<AndroidJavaObject>("setFlags", kIntent_FLAG_ACTIVITY_NEW_TASK | kIntent_FLAG_ACTIVITY_CLEAR_TASK);
currentActivity.Call("startActivity", intent);
currentActivity.Call("finish");
var process = new AndroidJavaClass("android.os.Process");
int pid = process.CallStatic<int>("myPid");
process.CallStatic("killProcess", pid);
}
}
Unity 安卓端重启自身
最新推荐文章于 2024-07-10 03:11:56 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)