3
votes
Android deep linking is not working
===================================
 Android link:-notification://id=notificationid

1:-In manifest

      <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

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

                    <data
                        android:host="id"
                        android:scheme="notification" />
                </intent-filter>       

2:-and coding side

 @Override
        protected void onResume() {
            super.onResume();        
            Intent intent = getIntent();
            String string=intent.getAction();
            Uri data = intent.getData();
            Log.d("hello","cgbdsuyfdkv");
        }   

but its not working please any body can help me !!!!!

4
is your code run for first time?Chetan Joshi
yes run my code and my url like this (notification://id=notificationid)but can its can not workAshutosh Srivastava
But second time you could not get updated notification id ? rightChetan Joshi
yes i can not getting updated value whyAshutosh Srivastava
check my answer belowChetan Joshi

4 Answers

1
votes

you can simply modify your url

Android link:-notification://id=notificationid instead of
Android link:-notification://page?id=notificationid  //page is host name
I tried a lot and find out this is working for me.
  1. manifest code

               <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.BROWSABLE" />
    
                <data
                    android:host="page"
                    android:scheme="notification" />
            </intent-filter>       
    

2.java code #get your notification id here

Intent intent = getIntent();
    String string = intent.getAction();
    Uri data = intent.getData();
    if (data != null) {
        String path = data.getPath();
        String path1 = data.getPath();
        providerUrl = intent.getData().toString();
        UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
        sanitizer.setAllowUnregisteredParamaters(true);
        sanitizer.parseUrl(providerUrl);
        String id = sanitizer.getValue("id");
        if (id != null)
            Log.d("notification id", id);
    }
1
votes

Add onNewIntent() method to your Activity and then use intent object which is variable in OnNewintent() method , which has updated method.

onNewIntent() is meant as entry point for singleTop or singleTask activities which already run somewhere else in the stack and therefore can't call onCreate(). From activities lifecycle point of view it's therefore needed to call onPause() before onNewIntent(). I suggest you to rewrite your activity to not use these listeners inside of onNewIntent(). For example most of the time my onNewIntent() methods simply looks like this:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
//use this  intent object to get notificationid for second time 

}
0
votes

I think you Intent Filter is incomplete

<!-- To open app using link -->
    <intent-filter>
        <action android:name="android.intent.action.VIEW"></action>
        <category android:name="android.intent.category.DEFAULT"></category>
        <category android:name="android.intent.category.BROWSABLE"></category>
        <data android:scheme="http"
              android:host="yourdomain.com"
              android:pathPrefix="/someurlparam">
        </data>
    </intent-filter>
0
votes

1st step:

<intent-filter>
    <data android:scheme="your_uri_scheme" />
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

2nd step:

Uri data = this.getIntent().getData();
if (data != null && data.isHierarchical()) {
    String uri = this.getIntent().getDataString();
    Log.i("MyApp", "Deep link clicked " + uri);
}