4

I have to open my android application, when user clicks on a link that has my domain name. For example, lets say my domain is abc.com and i have posted this link on my Facebook page. When one of my friend(who has my application installed in his device) clicks on the link(in the device's browser), i should be able to open my website in a webview inside my application.

I am not sure how to get this work, but will intent-filters work? If so, can someone give me a piece of code to start with?

Vamsi Challa
  • 11,038
  • 31
  • 99
  • 149
  • 1
    possible duplicate of [Intercepting links from the browser to open my Android app](http://stackoverflow.com/questions/1609573/intercepting-links-from-the-browser-to-open-my-android-app) – AlexGreg Aug 27 '14 at 10:07

2 Answers2

12

You have to define a custom Intent Filter in the activity that should be launched when the url is clicked.

Let say that you want to launch the FirstActivity when a user click a http://www.example.com/ link on a web page.

Add this to your activity in the Manifest :

<activity android:name=".FirstActivity"
          android:label="FirstActivity">
  <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:host="www.example.com" android:scheme="http"></data>
  </intent-filter>
</activity>

When the user will click a HTML link to http://www.example.com/, the system will prompt either to use the browser or your app.

pdegand59
  • 12,776
  • 8
  • 51
  • 58
8

You can achieve this by using URI schemes (link e.g. myscheme://open/chat), add into your manifest this filter into e.g. main activity section (set your scheme name):

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

In your activity where you've set filter, you can get URI by calling this (in onCreate):

Uri intentUri = getIntent().getData();
Yuraj
  • 3,185
  • 1
  • 23
  • 42