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

inderbagga picture inderbagga · Nov 25, 2013 · Viewed 32.9k times · Source

i have tried link1, link2,link3, link4, link5, link6

Here's everything described about DeepLinking

What i want is the custom uri myapp://some_data, opens the native application installed in the device that requires some_data to initialise the application.

There are 2 scenarios in which the custom url can be clicked.

1) from within the SMS app, when user taps the link it should automatically open the installed otherwise open the googleplay store where the app is hosted

2) from within the body of a email message.

I have tried all the above listed links, but none of them works for me. I m having major problem with the scheme part.

Here's my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="MainActivity"
        android:label="@string/app_name"
         android:exported="true" >
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />

            <data android:scheme="inderbagga" />
        </intent-filter>
    </activity>
</application>

and here's the MainActivity.java

TextView tvText=(TextView)findViewById(R.id.tvid);

    if (getIntent().getAction() == Intent.ACTION_VIEW&&getIntent().getScheme().equals("inderbagga")) {
        Toast.makeText(getApplicationContext(), ""+getIntent().getScheme(), Toast.LENGTH_SHORT).show();
        Uri uri = getIntent().getData();
        // do stuff with uri
        tvText.setText(uri.toString());
    }
    else tvText.setText("NULL");

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.

in order to achieve the same, i 've used intent filters to set the scheme. and getIntent() to read the data that equals to a1b22c333 in the MainActivity.

Answer

prakash picture prakash · Nov 25, 2013

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);