Android Deep Linking issue ! How to use Custom Url scheme myapp://some_data

≡放荡痞女 提交于 2019-11-28 19:15:54

click link means this code will work

          <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="domain.com(google.com)"android:pathPrefix="/wp/poc1/(sufexes)" />

    </intent-filter>

get url data

        //get uri data
     Uri data = getIntent().getData();
     //get schma
     String scheme = data.getScheme(); // "http"
     //get server name
     String host = data.getHost(); // Ipaddress or domain name
    //get parameter
     String urltextboxname=data.getQueryParameter("name");
     //set value in textview
     name.setText(urltextboxname);

To be more specific, i want to open the native application when u url of type inderbagga://a1b22c333 is clicked, Either from sms application or gmail/yahoomail email message body.

There are many SMS and email applications available for Android. Precisely none of them know to convert inderbagga://a1b22c333 into clickable entries. You could build a list of all of those apps, contact each of their development teams, and ask them to add it.

Or, you could have your app watch for a particular http:// URL instead. While the user would be presented with a chooser, to view that URL within your app or a Web browser, at least it will be clickable.

You might also want to try out this library which facilitates declaring deep links and extracting out the parameters you need:

https://github.com/airbnb/DeepLinkDispatch

It allows you to declare the URI you're interested in and the parameter you'd like to extract through annotations, without having to do the parsing yourself.

It looks like the problem you are having is that your email and SMS client are not parsing the URI scheme and path correctly. Most do not allow you to enter in a URI scheme directly. Additionally, if the app is not installed, you need to fallback to the Play Store so the user is given a good experience.

In order to do this, you need to call the URI scheme in client side JS. You can setup a simple web host and use this script:

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

Or, you can use a service like branch.io which automatically assembles this client side JS for you in addition to working on desktop and iOS as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!