invoking application activity from url in email

694 views Asked by At

I am having an application with 4 different activities.

  • activity 1 is for Live screen
  • activity 2 is for Playback screen

I am implementating scenario to launch the activity from a url send to email client (Gmail).

User receive the email and it has 2 links :

  • Link 1 is to open Live screen ( activity 1)
  • Link 2 is to open Playback screen ( activity 2)

In my application manifest file, i created intent filter for activity 1 and activity 2.

  <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" /> 
  </intent-filter>

Issues

  1. when i use custom scheme (e.g "myapp" ) the link inside the Gmail is not clickable. I can only click the link if i add scheme as "http" . is it a drawback on android email clients? How to overcome this issue and use a clickable custom url.
  2. since i have added two intent filters inside my manifest file , when i click on the url link in the email, it opens a selector dialog to choose the application. Inside that , my application icon is shown 2 times. I want my application icon to be shown only once . and based on the link, it should open activity 1 or 2. it seems the icon appears number of times as per the intent filters given inside the manifest file. How can i overcome this issue
2

There are 2 answers

0
Bryan Herbst On

when i use custom scheme (e.g "myapp" ) the link inside the Gmail is not clickable. I can only click the link if i add scheme as "http" . is it a drawback on android email clients? How to overcome this issue and use a clickable custom url.

Unfortunately it is up to GMail whether or not it wants to play nice with custom URL schemes.

One commonly used solution is to link to a website that redirects the user to the custom URL scheme.

since i have added two intent filters inside my manifest file , when i click on the url link in the email, it opens a selector dialog to choose the application. Inside that , my application icon is shown 2 times. I want my application icon to be shown only once . and based on the link, it should open activity 1 or 2. it seems the icon appears number of times as per the intent filters given inside the manifest file. How can i overcome this issue

Only register one intent filter for each unique URI scheme that you want to intercept.

If your app needs to parse the data to determine where to go, then you can either put that logic in your main activity or create a special Activity for the sole purpose of parsing links and put the intent filter in that Activity's manifest entry.

If you are really using <data android:scheme="http" />, then your <data> tags are simply too vague. You can make them more specific by adding host or path attributes so that your links only resolve to one of your intent filters instead of all of them.

0
Alex Austin On

Disclaimer: I work for branch.io and think about mobile linking for approximately 18 hours a day.

Issue 2 first, since it's easier. It shows the icon twice because you've registered your app twice for the same URI. Just like if you have multiple browsers on your phone, they all register for the http scheme so that when an http link is clicked, the individual browser icons appear in the selector.

Now Issue 1, regarding opening up your app from email. First off, you can use a Branch link to do all of this automatically for you. It's super easy and I highly recommend it. However, if you have infinite resources and want to build it yourself, or just want to understand how it works, let me explain below.

First off, from a best practices perspective, you never want to just put your URI scheme (myapp://) in a public message because all browsers throw an error message if the app is not installed. You need some client side javascript to fall back to the Play Store. The worst part about this is that almost all browsers handle this differently. For example, Twitter's webview is very different than Chrome.

Here's some example client side JS to open up the Facebook app and deep link to a post, but fallback to the Play Store properly if it's not installed. It handles some of the most common browsers.

<script type="text/javascript">
    window.onload = function() {
        var method = 'iframe';
        var fallbackFunction = function() {
            if (method == 'iframe') {
                window.location = "market://details?id=com.facebook.katana";
            }
        };
        var addIFrame = function() {
            var iframe = document.createElement("iframe");
            iframe.style.border = "none";
            iframe.style.width = "1px";
            iframe.style.height = "1px";
            iframe.src = "fb://page/838619192839881";
            document.body.appendChild(iframe);
        };
        var loadChromeIntent = function() {
            method = 'intent';
            document.location = "intent://page/838619192839881#Intent;scheme=fb;package=com.facebook.katana;end";
        };
        if (navigator.userAgent.match(/Chrome/) && !navigator.userAgent.match("Version/")) {
            loadChromeIntent();
        }
        else if (navigator.userAgent.match(/Firefox/)) {
            window.location = "fb://page/838619192839881";
        }
        else {
            addIFrame();
        }
        setTimeout(fallbackFunction, 750);
    };
</script>

Again, Branch does it all for you, and allows you to deep link through the Play Store for personalization of the new user experience.