10

I've implemented a custom URL scheme on Android and iOS, with the idea that we will send an "activation" email to the user, who clicks a link which spawns the native app.

Technically, we send an HTML formatted email with a link such as:

<a href="myapp://activate/accountId/uniquetoken">Click to activate</a>

On iOS it works fine, but on Android, it doesn't work.

I've seen a few other S.O posts and similar things that android itself should handle the custom URL scheme, but indicate it is the Chrome browser and the GMail for Android app which is stripping these custom myapp:// url's out.

As per the advice of some of those posts, I've tried creating an intent url. I've tried all of the following

intent://activate#Intent;scheme=myapp;package=com.mycompany.myapp;end

#Intent;action=activate;end

#Intent;component=com.mycompany.myapp/.ui.MainActivity;end

intent://#Intent;component=com.mycompany.myapp/.ui.MainActivity;end

but none of them worked. None were clickable from within the GMail for android app on Android 6, and the android documenation on the format for intent uri's is incredibly poorly documented. The best I can find is "programmatically create your intent in Java, then call .toUri on it", (which is how I produced most of the broken intent uri's above)

Any help would be much appreciated


Update 1. Here's my activity and intents from the Android manifest

    <activity android:name=".ui.MainActivity" android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <!-- load via URL scheme -->
        <intent-filter>
            <data android:scheme="myapp" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

I've tried setting up a web server, which "reflects" back to the custom app scheme, and this DOES work for both Android and iOS

<a href="http://mycloudserver.net/myapp/activate/accountId/uniqueToken">Click</a>

That page does a 302 redirect to

myapp://activate/accountId/uniqueToken

The web browser (Chrome for android) follows this redirect, which causes the native app to launch, so that does provide a solution (of sorts) for the Gmail for android app.

It introduces an artificial dependency on a cloud server though, which would be nice to avoid.

On iOS it leaves behind an empty page in the Safari browser too, which is minor but unfortunate.

1
  • For myapp://activate/accountId/uniqueToken, you may need to include the full path in your Intent, or at least far enough in the path that the intent-filter in your AndroidManifest.xml can identify it. Could you paste your AndroidManifest.xml's intent-filter that handles the url scheme?
    – nicobatu
    Aug 4, 2016 at 23:01

1 Answer 1

8

As you have discovered, there is no perfect solution for this. Custom URL schemes are often not recognized as clickable links, and iOS, Android, and Chrome all have different rules about what is allowed. And though this is less of an issue in your specific situation, there is also no convenient way to handle devices without the app installed.

Routing through a cloud destination really is the only reliable way to accomplish this, and at Branch.io, we use a solution similar to what you have put together. If you use a cloud destination with smart redirection to combine Universal Links (iOS 9+), URL schemes (iOS < 8, basic Android), App Links (newer Android), and Chrome Intents (Chrome on Android), then you have handled the majority of situations that would come up. The side benefit is you also have a way to deal with devices without the app, since they will see the content at the cloud destination if all of the above methods fail. On iOS you can also sometimes fire a final redirect after the app is launched, so that there is no blank screen left over, but this doesn't work in all situations.

Incidentally, the above is exactly what Branch provides as a free service. You might give it a look!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.