AndroidStudio里
public void doRestart(int Ntime)
{
Log.d("Unity", "========restart "+Ntime);
Intent restartIntent = getPackageManager()
.getLaunchIntentForPackage(getPackageName() );
PendingIntent intent = PendingIntent.getActivity(this, 0,restartIntent,0);
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
manager.set(AlarmManager.RTC, System.currentTimeMillis()+Ntime, intent);
finish();
android.os.Process.killProcess(android.os.Process.myPid());
}
unity中的调用
public static void Restart(int delay)
{
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject mainActivity = jc.GetStatic<AndroidJavaObject>("currentActivity");
mainActivity.Call("doRestart", delay);
jc.Dispose();
mainActivity.Dispose();
}
网友评论