美文网首页
Unity调用安卓重启应用

Unity调用安卓重启应用

作者: 三十五岁是码农 | 来源:发表于2018-02-13 12:38 被阅读0次

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();
  }

相关文章

网友评论

      本文标题:Unity调用安卓重启应用

      本文链接:https://www.haomeiwen.com/subject/etyjtftx.html