- Home /
Open Android App from URL
I have a game with a level editor.
I hope that users can share this levels.
The idea is generate a URL with a intent that open the game, and the level.
(Or if the user dont have the game installed, open a playstore url)
But i have no idea of how to do this.
I dont know how to open the game by a link in the navegator and dont know how to "pass" a param to the game to say open the level "X".
I read about intent, but people are using android studio, java, manifest and other things that i dont know if i need or not...
Someone did something like this?
Im lost in this area :S
Answer by cronem · Feb 22, 2017 at 09:14 AM
Hello,
I've just run into a similar issue, and I could figure out how to open the App from a URL, at least.
First, open your .apk build in the Android Studio and edit the AndroidManifest file in there. In my case, my app bundle identifier is "com.vizAR.OppaAR" and I wanted to open the app by accessing "www.eduardo-cg.com/test", so I add this info into the AndroidManifest, inside my main activity:
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<category
android:name="android.intent.category.DEFAULT" />
<category
android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="www.eduardo-cg.com"
android:path="/test" />
</intent-filter>
And at my site I created a button with the following html code:
<a href="intent://www.eduardo-cg.com/test#Intent;scheme=http;package=com.vizAR.OppaAR;end;">Open App</a>
So when I click at the button, it opens the app, if it's installed on the phone, or the PlayStore, if it isn't.
I still haven't figure out how to pass a param to the game, but it's the first step, anyway ;) If you did resolve that, please tell me.
Good luck!
Great job! Thanks! i am looking to pass a parameter too :/
I used this code and I changed the package doesn't seem to work for me.
Answer by CartageVR · Jun 15, 2017 at 05:23 PM
Hi, here my solution working for me to complete cronem answer. First , you complete URL with args like this for a string in this example
<a href="intent://www.eduardo-cg.com/test#Intent;scheme=http;package=com.vizAR.OppaAR;S.namestring=mystring;end;">Open App</a>
The "S" at the beginning of the "namestring" parameter defines it as a String. Other types can be:
String => 'S' Boolean =>'B' Byte => 'b' Character => 'c' Double => 'd' Float => 'f' Integer => 'i' Long => 'l' Short => 's'
then create a start code like this example :
public class getExtraName : MonoBehaviour {
// Use this for initialization void Start () {
string yourname = "";
AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject intent = currentActivity.Call<AndroidJavaObject>("getIntent");
bool hasExtra = intent.Call<bool>("hasExtra", "namestring");
if (hasExtra)
{
AndroidJavaObject extras = intent.Call<AndroidJavaObject>("getExtras");
yourname = extras.Call<string>("getString", "namestring");
}
} }
Hope helpfull
Add comment · Share
Nice, I'll try that!
Anyway, the solution I found earlier was to use this plugin, which worked really well: https://www.assetstore.unity3d.com/en/#!/content/30430 .
Cheers,
Answer by majaus · Jul 16, 2017 at 03:53 PM
Thanks to both. Finally, im using the deep link plugin. In the plugin documentation, it say about use a url like this:
test
But if you want that Play Store open if the aplication is not intalled, you can write this:
test2
I noticed that are a conflict whit manifest.xml if you use google play services pluggin, im not using services for the moment, but in future i need to study how to resolve this issue...