Android/iOS: Launch from within a Unity app another Unity app

Hi!

(I posted this in Android Development but it applies to both Android and iPhone so if there’s a better section for this post I apologize.)

My question:

Is it possible to launch another Unity application from within a Unity application? Basically I want to be able to press a “Start other app”-button inside Unity app #1 that launches this other Unity app (#2), or if it’s not yet downloaded takes me to AppStore/PlayStore.

Is something like Application.OpenURL() interesting here? Or what would be the best approach? I’m using Unity 4.3.2 btw.

Thanks!

3 Likes

i’ve found Application.OpenURL() to work but you will be better putting it in an if statement with and else

for example only

if(!app)
{
     if (Input.GetButton("Start"))
      {
      Application.OpenURL("Your URL");
       }
  else
      {
      Application.OpenURL("YourOtherURL");
       }
}

make sure you have a function that can detect you phone and find your that way it will work properly mine works by checking if the URL address is there first so make sure your URL is right you my need to check your phone folder structure first before approaching this of just have

  if (Input.GetButton("Start"))
      {
      Application.OpenURL("Your URL");
       }

and keep it simple but if its not there it will not open

Thanks for the answer!

I think I need to specify a bit more: Can I somehow check if an app is installed? And if that app is installed can I make the phone launch it? Or if it’s not installed redirect the user/phone to AppStore/PlayStore?

I would be very grateful if I could get example code on these specific lines, if it’s even possible. Maybe I can do something with “com.company.appname”?

You can use something like this on Android:

public void launchApp(String packageName)
{
    Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage(packageName);
    if (intent != null)
    {
        // Activity was found, launch new app
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
    else
    {
        // Activity not found. Send user to market
        intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse("market://details?id="+packageName));
        startActivity(intent);
    }
}

Not tested, but should work.

2 Likes

Thanks for your reply! I’m not sure this is what I’m looking for though, since I need it to work in Unity (C# scripts) and preferably something that will work with both iOS and Android, i.e. a Unity method. But maybe I’m misunderstanding something?

Hi LouiseW, have you found any answer to your original question?

I as well need to make my app detect if another app is installed on iOS device. And then launch it from my unity app.

Hi!

Sorry, I haven’t checked in here for over a week so I haven’t seen your question.

I have not found the answer I was looking for and since I have some deadline “issues”, I decided to use “Application.OpenURL (“link-to-my-other-app-in-GooglePlay/AppStore”);” instead. So when the user clicks the button that leads them to the store, they can choose to install the app (or open if already installed). This is a last solution I guess, but it works for me this time.

If you somehow find the answer to my original question, I would be very grateful if you would write the answer here. :slight_smile:

1 Like

See this plugin hope it may help you…

The right question here is: Can we detect if apps are installed on device using custom URL schemes? We can’t do this from Unity API therefore we need a plugin.

Davesh, can your plugin do this or it can only launch those apps listed in description?

Sorry, mtusan, My plugin will only launch another application.

how to open installed application in unity.

Ganesh, have you read the my plugin’s description?

This plugin is for Android and iOS so it will work on Android and iOS device only, it will not work in Unity Editor.
After integrating this plugin you can launch dial pad, message, gmail, skype, facebook etc from your unity app.

AppLauncher is very cheap and easy to integrate.

Hi, it is a year late but you can do it by

            bool fail = false;
            string bundleId = com.google.appname; // 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)
            { //open app in store
                Application.OpenURL("https://google.com");
            }
            else //open the app
                ca.Call("startActivity",launchIntent);

            up.Dispose();
            ca.Dispose();
            packageManager.Dispose();
            launchIntent.Dispose();
23 Likes

kingandroid - Thanks for the share. Works like a charm.

thanks so much its working perfect :slight_smile:

so I need to declare the “fail” variable? or is there something I miss?

also, I just need to set my target app data at this string right?

“com.unity3d.player.UnityPlayer”

so that’s say I have an app named “ABC”

I just replace it like

“com.unity3d.player.ABC”??

Yes you need to declare
bool fail = false; first.
And just leave the unity name as it is, don’t change it to your app name

sorry I copy the code from below.
So I miss a spot on the first line XD.
I apologize for that…

Ok…I’m still kind of stuck in it.
where should I set my target app name instead?
and also do I need a .jar file to call my apps with your code?

I edited my answer, so yeah there was not any bool before, no need to apologize for that xD

Hmm if you see my answer now, I put comment showing where to put your target bundle id not the name (“com.companyname.applicationame” in build setting), it is the
string bundleId = com.google.appname; // replace it to your target bundle ID

you dont need any .jar, it is default built-in within unity

Yes! It works!!! My app has come to life!!!

Thank you!!! kingandroid (like a billion thanks)

I don’t know if it is my fantasy, or do you just happen to have an account called “king ios”?