3

I want to be able to handle deep links like this :

appnm://typeA/12
appnm://typeA/42
appnm://typeA/99
....

appnm://typeB/43
appnm://typeB/092
appnm://typeB/....
  1. Do I have to make two activities - for type A and for type B. Or can I handle both in one activity ? For example, would that work :

    data android:scheme="appnm" android:host="" android:pathPrefix="/" />

  2. when I type in some note on the phone "http:// ..." it automatically gives me the option to enter it like a link. However in my case "appnm://..." it doesn't. So how can I test the deeplink with a custom scheme ?

BVtp
  • 2,308
  • 2
  • 29
  • 68
  • 2
    Check out this post http://stackoverflow.com/questions/31876003/how-to-test-custom-url-scheme-in-android Does this answer your questions? – Shubhankar S Jan 30 '16 at 12:02
  • yes , thank you, haven't seen that post in my search. However , I am still not sure about my first question. Do I need to use two activities or one? ( typeA and typeB ) – BVtp Jan 30 '16 at 17:21

2 Answers2

2

You can add mime types which will specify what kind of data is being deeplinked. If you want all deeplinks to go to the same activity, you just declare the intent filter within that activity with only the uri scheme. However, declaring a mime type can be used to direct different kind of data to different activities.

Does this clarify your doubt?

Shubhankar S
  • 460
  • 2
  • 8
  • But as far as I understand, the mime types indicate some specific kind of data ( images ,audio etc. ). How would I use it here? I need to know if the link was `appnm://typeA/...` or `appnm://typeB/...` so I would know what fragment to open when the app launches. Thank you. – BVtp Jan 30 '16 at 17:40
  • 1
    When your activity is triggered on receiving the URI scheme, you can get the data of the trigger like : Intent intent = getIntent(); Uri data = intent.getData(); This can help you differentiate the trigger and launch different activities accordingly – Shubhankar S Jan 30 '16 at 17:49
  • that I know, but how would I handle my case in the manifest? can I type only `android:scheme="appnm"` without host and pathPrefix ? Thanks! – BVtp Jan 30 '16 at 17:51
  • There are other attributes that you can set as well for the intent filter namely : `android:path` `android:pathPrefix` You can reference this developer page http://developer.android.com/guide/topics/manifest/data-element.html Setting different intent filters for different path prefixes might do the trick! – Shubhankar S Jan 30 '16 at 18:06
  • yes but my problem is the 'host' attribute , which can be of two types.. so would I have to separate it to two activities? – BVtp Jan 30 '16 at 19:41
  • 1
    What is your end goal? If you want two different host's to go to the same activity, you can declare two intent filters within the same activity (or not declare host at all if that's acceptable). If you want different hosts to go to different activities, you can make separate intent filters for each activity specifying different host for each – Shubhankar S Jan 31 '16 at 07:19
0

DeepLinkDispatch Library by airbnb will help you to handle all Custom URLs.

Explained how to use, at the library page in github

javadroid
  • 1,421
  • 2
  • 19
  • 43
Sumit Jain
  • 1,100
  • 1
  • 14
  • 27