Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get gmail for android to open a custom URL scheme, or an intent:// URL

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.

like image 531
Orion Edwards Avatar asked Aug 04 '16 22:08

Orion Edwards


People also ask

What is URL scheme in Android?

In Android 1.0, the Android URI scheme deep linking mechanism was created. It allows the developer to register their app for a URI (uniform resource identifier) in the operating system for a specific device once the app is installed.

What is deep linking in Android?

In Android, a deep link is a link that takes you directly to a specific destination within an app. The Navigation component lets you create two different types of deep links: explicit and implicit.


1 Answers

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!

like image 125
Alex Bauer Avatar answered Sep 27 '22 17:09

Alex Bauer