You achieve this by Deep linking in your app.
First of all you need to add intent filters for incoming links.
<action>
Specify the ACTION_VIEW intent action so that the intent filter can be
reached from Google Search.
<data>
Add one or more tags, each of which represents a URI format
that resolves to the activity. At minimum, the tag must include
the android:scheme attribute.
You can add more attributes to further
refine the type of URI that the activity accepts. For example, you
might have multiple activities that accept similar URIs, but which
differ simply based on the path name. In this case, use the
android:path attribute or its pathPattern or pathPrefix variants to
differentiate which activity the system should open for different URI
paths.
<category>
Include the BROWSABLE category. It is required in order for the intent
filter to be accessible from a web browser. Without it, clicking a
link in a browser cannot resolve to your app.
Also include the DEFAULT
category. This allows your app to respond to implicit intents. Without
this, the activity can be started only if the intent specifies your
app component name.
I have used this url for launch my app “http://www.example.com/gizmos”
Look at the my Manifest.xml file,
<activity
android:name="com.example.android.GizmosActivity"
android:label="@string/title_gizmos" >
<intent-filter android:label="@string/filter_view_http_gizmos">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data android:scheme="http"
android:host="www.example.com"
android:pathPrefix="/gizmos" />
<!-- note that the leading "/" is required for pathPrefix-->
</intent-filter>
<intent-filter android:label="@string/filter_view_example_gizmos">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "example://gizmos” -->
<data android:scheme="example"
android:host="gizmos" />
</intent-filter>
</activity>
And notice that the two intent filters only differ by the <data>
element.
<intent-filter>
...
<data android:scheme="https" android:host="www.example.com" />
<data android:scheme="app" android:host="open.my.app" />
</intent-filter>
It might seem as though this supports only https://www.example.com and
app://open.my.app. However, it actually supports those two, plus
these: app://www.example.com and https://open.my.app.
Read data from incoming intents
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
}
Test your deep links
The general syntax for testing an intent filter URI with adb is:
$ adb shell am start
-W -a android.intent.action.VIEW
-d <URI> <PACKAGE>
For example, the command below tries to view a target app activity that is associated with the specified URI.
$ adb shell am start
-W -a android.intent.action.VIEW
-d "example://gizmos" com.example.android