Android - Deeplink

<div>
	<p>Buy our latest PC parts.</p>
	<a href="app://myapp/products/cpu"> </a>
</div>
<activity android:name=".ProductsActivity">
    <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="app"
              android:host="myapp"
              android:pathPrefix="/products/" />
    </intent-filter>
</activity>
Element Description
<activity android:name=".ProductsActivity"> Defines the activity to be launched once the link is tapped.
android:scheme="app" Sets the protocol. It defines the app (can be anything) part of the URL app://myapp/products/cpu included in the website.
android:host="myapp" Sets the host. It defines the myapp (can be anything) part of the URL app://myapp/products/cpu included in the website.
android:pathPrefix="/products/" /> Sets the path prefix. It defines the /products/ part of the URL app://myapp/products/cpu included in the website.
public class ProductActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_planet);

        Intent intent = getIntent();
        String action = intent.getAction();
        Uri data = intent.getData();

        if (Intent.ACTION_VIEW.equals(action) && data != null) {
            String ProductName = data.getLastPathSegment();
          
          	if (ProductName.equals("cpu")) {
            	// Do something. For example, query the database for information on this product.
            }
        }
    }
}

Assuming that the URL https://www.myapp.com/ leads to an existing website, the deep link in it would look like this.

Code: html

<div>
	<p>Buy our latest PC parts.</p>
	<a href="https://www.myapp.com/products/cpu"> </a>
</div>

Accordingly, the Androidmanifest.xml file will contain the following.

Code: xml

<activity android:name=".ProductsActivity">
    <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="https"
              android:host="www.myapp.com"
              android:pathPrefix="/products/" />
    </intent-filter>
</activity>

 Previous