From b270433188d0dc531a7e706bca2ba04aae27ca14 Mon Sep 17 00:00:00 2001 From: oxmc <67136658+oxmc@users.noreply.github.com> Date: Fri, 13 Jan 2023 16:53:01 -0800 Subject: [PATCH] Update AssetsDownloader.cs --- Assets/Scripts/AssetsDownloader.cs | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Assets/Scripts/AssetsDownloader.cs b/Assets/Scripts/AssetsDownloader.cs index 4241770..0e7c151 100644 --- a/Assets/Scripts/AssetsDownloader.cs +++ b/Assets/Scripts/AssetsDownloader.cs @@ -14,6 +14,52 @@ using Newtonsoft.Json.Linq; namespace QuestAppLauncher { + private bool installApp(string apkPath) +{ + bool success = true; + //GameObject.Find("TextDebug").GetComponent().text = "Installing App"; + + try + { + //Get Activity then Context + AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); + AndroidJavaObject currentActivity = unityPlayer.GetStatic("currentActivity"); + AndroidJavaObject unityContext = currentActivity.Call("getApplicationContext"); + + //Get the package Name + string packageName = unityContext.Call("getPackageName"); + string authority = packageName + ".fileprovider"; + + AndroidJavaClass intentObj = new AndroidJavaClass("android.content.Intent"); + string ACTION_VIEW = intentObj.GetStatic("ACTION_VIEW"); + AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent", ACTION_VIEW); + + + int FLAG_ACTIVITY_NEW_TASK = intentObj.GetStatic("FLAG_ACTIVITY_NEW_TASK"); + int FLAG_GRANT_READ_URI_PERMISSION = intentObj.GetStatic("FLAG_GRANT_READ_URI_PERMISSION"); + + //File fileObj = new File(String pathname); + AndroidJavaObject fileObj = new AndroidJavaObject("java.io.File", apkPath); + //FileProvider object that will be used to call it static function + AndroidJavaClass fileProvider = new AndroidJavaClass("android.support.v4.content.FileProvider"); + //getUriForFile(Context context, String authority, File file) + AndroidJavaObject uri = fileProvider.CallStatic("getUriForFile", unityContext, authority, fileObj); + + intent.Call("setDataAndType", uri, "application/vnd.android.package-archive"); + intent.Call("addFlags", FLAG_ACTIVITY_NEW_TASK); + intent.Call("addFlags", FLAG_GRANT_READ_URI_PERMISSION); + currentActivity.Call("startActivity", intent); + + //GameObject.Find("TextDebug").GetComponent().text = "Success"; + } + catch (System.Exception e) + { + //GameObject.Find("TextDebug").GetComponent().text = "Error: " + e.Message; + success = false; + } + + return success; +} /// /// Downloads assets (app icons packs and names files) from configured repos. ///