Android 从app link启动活动时,intent.data为空

Android 从app link启动活动时,intent.data为空,android,null,intentfilter,applinks,Android,Null,Intentfilter,Applinks,我看了相关的,所以他们似乎没有解决这个问题 该应用程序支持应用程序链接,网站具有.well-known/assetlinks.json 在电子邮件中单击应用程序链接时,例如 主要活动应该出现 onCreate()应该从intent.data获取URI数据 主活动应根据URI数据进行自我更新 使用有效的应用程序链接从冷启动启动启动应用程序时,intent.data始终为空。不过,若应用程序一直在运行或在后台运行,则onNewIntent()中的URI intent.data不会为null,并且

我看了相关的,所以他们似乎没有解决这个问题

该应用程序支持应用程序链接,网站具有.well-known/assetlinks.json

在电子邮件中单击应用程序链接时,例如

  • 主要活动应该出现
  • onCreate()应该从intent.data获取URI数据
  • 主活动应根据URI数据进行自我更新
使用有效的应用程序链接从冷启动启动启动应用程序时,intent.data始终为空。不过,若应用程序一直在运行或在后台运行,则onNewIntent()中的URI intent.data不会为null,并且可以正常工作

不知道我错过了什么。它运行在GalaxyJ3Prime和安卓7.0上。这里是配置。如何从冷启动获取intent.data URI

    <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>


尝试将
android:launchMode=“singleInstance”
更改为
android:launchMode=“singleTask”
结果表明,这是可行的。其他地方出现异常,导致启动活动跳过对URI数据的更新。发布解决方案,以防对其他人有用

为了追踪,我在Android Studio的app link冷启动期间将调试器连接到设备进程,如下所示:

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
然后运行->调试->选择带有链接的调试配置

进行API调用,并在启动活动中显示一个带有忙指示器的PopupWindow。弹出窗口正在引发异常:

BadTokenException: Unable to add window -- token null is not valid; is your activity running?
要使弹出窗口正常工作,在“活动启动周期”完成后,将在onCreate()中显示弹出窗口

activityRootView.post {
  handleAppLinkIntent(intent) // show busy popup and do stuff with intent.data
}
看看这个。您应该重写onNewIntent,然后处理其中的数据

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    // do stuff with intent
}