How do I launch my Unity game from a URL in Android?

I’ve managed to launch my app from Safari using a custom URL type in an iOS build, and I pass that URL into the PlayerPrefs by using some code in AppController.mm.

How can I do the same thing on an Android build, launching my app to handle a custom URL scheme, and passing that URL into PlayerPrefs?

You’ll need to use the Android intent android.intent.category.BROWSABLE.

The example Android app Photostream does this.

In its AndroidManifest.xml you can see where it sets up the intent:

<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="flickr.com"
          android:pathPrefix="/photos/" />
    <data android:scheme="http"
          android:host="www.flickr.com"
          android:pathPrefix="/photos/" />
</intent-filter>

You can see the data being retrieved from the intent in PhotostreamActivity in the getUser function.

You can do something like this:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Uri uriUsedToLaunch = getIntent().getData();
}