Android App link not opening desired intent

36 Views Asked by At

I am having a app with two pages only LauncherActivity and HomeActivity. Both these activities are defined in manifest as follows

  <activity
        android:name=".activities.LauncherActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:exported="true"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/AppThemeMap"
        android:windowSoftInputMode="stateHidden|adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  <activity
        android:name=".activities.HomeActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/AppThemeMap">
        <intent-filter android:autoVerify="true">
            <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.xyz.net"
                android:pathPrefix="/corp" />
        </intent-filter>
    </activity>

I have used Android app links in my app so that whenever user clicks on designated URL, my app Home page opens.

When app is in history stack it opens Home page as expected but if app is in killed state it opens Launcher page first then redirect to Home.

I want Direct Home page opens every time. how it can be achieved ?

1

There are 1 best solutions below

0
Davit Hovhannisyan On

To make sure that your link will always open HomeActivity and not LauncherActiviy, you can use Android App LInks with the "autofill" attribute.

You need to change your manifest like this:

<activity
    android:name=".activities.HomeActivity"
    android:exported="true"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@style/AppThemeMap">
    <intent-filter android:autoVerify="true">
        <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.xyz.net"
            android:pathPrefix="/corp" />
    </intent-filter>

    <!-- there you need to add the "autofill" attribute to the intent filter -->
    <intent-filter android:autoVerify="true" android:autofill="true">
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

By this, you indicate that Android should directly open the HomeActiviyu when the app is not running or killed; this method will help you pass the LauncherActiviy. Make sure that you have properly set up App Links on your website to associate the URLs with your app. Additionally, ensure that the android:autoVerify="true" attribute is set.