- Home /
Launch an app from within another app
Hi, I'm triying to launch an already inastalled Adroid/iOS app from within another app; I searched far and wide and tried all known ways like:
// package = apk name
public void RunApk(string package){
string filepath = "";
#if UNITY_EDITOR
filepath = Application.dataPath + string.Format("/StreamingAssets/{0}", package);
#else
filepath = Application.persistentDataPath + "/" + package;
if (!File.Exists(filepath)) {
WWW loadAPK = new WWW("jar:file://" + Application.dataPath + "!/assets/" + package);
while (!loadAPK.isDone) {}
File.WriteAllBytes(filepath, loadAPK.bytes);
}
#endif
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = filepath;
Process.Start(startInfo);
Someone has an idea?
Thank you.
Giusort
see this nice plugin it may help you to launch any other app in android and ios... http://unitydevelopers.blogspot.in/2017/06/launch-any-app-from-unity-android-ios.html
Answer by Vandarthul · May 18, 2017 at 11:48 AM
Hey @Giusort , I can offer you a way to do it in Android but you will still need to find a way to do it in iOS. You can wrap it up in Platform Dependent Compilation like #if UNITY_ANDROID and use that way.
Try this:
public void LaunchApp(string package, string storeLink = null)
{
bool fail = false;
string bundleId = package; // your target bundle id
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
AndroidJavaObject launchIntent = null;
try
{
launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
}
catch (System.Exception e)
{
fail = true;
}
if (fail && storeLink != null)
{ //open app in store
Application.OpenURL(storeLink);
}
else //open the app
ca.Call("startActivity", launchIntent);
up.Dispose();
ca.Dispose();
packageManager.Dispose();
launchIntent.Dispose();
}
package is bundleIdentifier of app, such as "com.facebook.katana" and optional parameter is the store link of the app in case the app is not found in device, you can leave it as null and it will only try to open the app if it exists.
Your answer
Follow this Question
Related Questions
Detect if app is installed on iOS 0 Answers
Password for launching app? 1 Answer
Detect if app is installed on Android 2 Answers
Start iOS app from a Unity3d iOS app 1 Answer