Android - Create launcher Icon for the deeplink

102 Views Asked by At

Here is my main application launcher activity

<activity android:name="com.myapp.book.WebActivity"
    android:launchMode="singleTask"
    android:theme="@style/MyTheme.NoActionBar"
    android:exported="true">
    <intent-filter>
        <data android:scheme="com.myapp.book" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts_main" />
</activity>

I could open the deeplinks using code below from another app.

String deeplink="com.myapp.book://mybook.in/orders";
Intent intent = new Intent();
ComponentName componentName = new ComponentName(getPackageName(), "com.myapp.book.WebActivity");
intent.setComponent(componentName);
intent.setAction("android.intent.action.VIEW");
intent.setData(Uri.parse(deeplink));
startActivity(intent);

I have got a requirement to create a new launcher icon for a deeplink. How to do it?

I have tried below. But no luck.

<activity-alias
    android:name="om.myapp.book.Orders"
    android:targetActivity="android:name="com.myapp.book.WebActivity">
    android:exported="true"
    android:enabled="true"
    android:label="@string/Orders"
    android:icon="@drawable/orders"
    android:roundIcon="@drawable/orders"
    android:action="android.intent.action.VIEW"
    android:data="com.myapp.book://mybook.in/orders"
    >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts_orders" />
</activity-alias>
0

There are 0 best solutions below