기록용
public void Restart()
{
using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject pm = currentActivity.Call<AndroidJavaObject>("getPackageManager");
AndroidJavaObject intent = pm.Call<AndroidJavaObject>("getLaunchIntentForPackage", Application.identifier);
intent.Call<AndroidJavaObject>("setFlags", 0x20000000);//Intent.FLAG_ACTIVITY_SINGLE_TOP
AndroidJavaClass pendingIntent = new AndroidJavaClass("android.app.PendingIntent");
AndroidJavaObject contentIntent = pendingIntent.CallStatic<AndroidJavaObject>("getActivity", currentActivity, 0, intent, 0x8000000); //PendingIntent.FLAG_UPDATE_CURRENT = 134217728 [0x8000000]
AndroidJavaObject alarmManager = currentActivity.Call<AndroidJavaObject>("getSystemService", "alarm");
AndroidJavaClass system = new AndroidJavaClass("java.lang.System");
long currentTime = system.CallStatic<long>("currentTimeMillis");
alarmManager.Call("set", 1, currentTime + 1000, contentIntent); // android.app.AlarmManager.RTC = 1 [0x1]
Debug.LogError("alarm_manager set time " + currentTime + 1000);
currentActivity.Call("finish");
AndroidJavaClass process = new AndroidJavaClass("android.os.Process");
int pid = process.CallStatic<int>("myPid");
process.CallStatic("killProcess", pid);
}
}
출처
https://noodle1983.github.io/2018/11/17/RestartAndroidAppInUnityPureC/
반응형
'Unity' 카테고리의 다른 글
[Unity] 안드로이드/IOS 클립보드(텍스트 복사) 기능 구현 (0) | 2019.09.28 |
---|---|
[Unity] C# List 정렬 (0) | 2019.09.22 |
[Unity] 유니티와 AWS DynamoDB 연결 (1) | 2019.08.26 |
[Unity] 유니티와 AWS Cognito 연동하기 (2) | 2019.08.26 |
[Unity] 구글 플레이 게임 서비스(GPGS) 기능 스크립트 작성 (0) | 2019.08.11 |