4

I looked at related SO but they didn't seem to resolve this issue.

The app supports app linking and website has .well-known/assetlinks.json.

When clicking app link in email, say https://staging.xyz.com/v3/info/7vwD2yjW, the

  • main activity should appear
  • onCreate() should get URI data from intent.data
  • main activity should update itself based on URI data

Launching app from a cold start with a valid app link, the intent.data is always null. However if app had been running or in background, URI intent.data is not null in onNewIntent() and works fine.

Not sure what I am missing. It's running on a Galaxy J3 Prime, Android 7.0. Here is the config. Any ideas how to get intent.data URI from cold start?

    <activity
        android:name=".activity.MainActivity"
        android:launchMode="singleInstance"
        android:screenOrientation="portrait">
        <tools:validation testUrl="https://staging.xyz.com/v3/info/7vwD2yjW" />

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <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="xyz.com"
                android:pathPattern="/.*/share" />
        </intent-filter>

        <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="xyz.com"
                android:pathPattern="/.*/info/.*" />
        </intent-filter>

        <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="*.xyz.com"
                android:pathPattern="/.*/share" />
        </intent-filter>

        <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="*.xyz.com"
                android:pathPattern="/.*/info/.*" />
        </intent-filter>
1192805
  • 988
  • 2
  • 10
  • 26

3 Answers3

2

Check out this question . You should override onNewIntent and then handle data from it.

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    // do stuff with intent
}
Ivan Vovk
  • 929
  • 14
  • 28
1

Turns out this works as-is. There was an exception elsewhere causing launch activity to skip updating from URI data. Posting resolution in case it may be useful to anyone else.

To track down I attached debugger to device process during cold start from app link in Android Studio like so:

adb shell am set-debug-app -w --persistent com.xyz.appname
adb shell am start -a android.intent.action.VIEW -d "https://staging.xyz.com/v3/info/7vwD2yjW" com.xyz.appname

Then Run -> Debug -> select debug config with link

An API call is made, and displays a PopupWindow with busy indicator in the launch activity. The popup was throwing exception:

BadTokenException: Unable to add window -- token null is not valid; is your activity running?

To get popup working, in onCreate() popup is displayed after activity startup cycle completes

activityRootView.post {
  handleAppLinkIntent(intent) // show busy popup and do stuff with intent.data
}
1192805
  • 988
  • 2
  • 10
  • 26
0

Try changing android:launchMode="singleInstance" to android:launchMode="singleTask"

Vamsi
  • 878
  • 1
  • 8
  • 25