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

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.

Hi, it is a bit of an old question, but anyone knows how to call the other app in a way that once finished it returns to your app?