简体   繁体   English

从应用程序链接启动活动时,intent.data为null

[英]intent.data is null when launching activity from app link

I looked at related SO but they didn't seem to resolve this issue. 我查看了相关的SO,但他们似乎并未解决此问题。

The app supports app linking and website has .well-known/assetlinks.json. 该应用程序支持应用程序链接,并且网站具有.well-known / assetlinks.json。

When clicking app link in email, say https://staging.xyz.com/v3/info/7vwD2yjW , the 单击电子邮件中的应用程序链接时,说https://staging.xyz.com/v3/info/7vwD2yjW

  • main activity should appear 主要活动应该出现
  • onCreate() should get URI data from intent.data onCreate()应该从intent.data获取URI数据
  • main activity should update itself based on URI data 主要活动应基于URI数据进行自我更新

Launching app from a cold start with a valid app link, the intent.data is always null. 从具有有效应用程序链接的冷启动启动应用程序,intent.data始终为null。 However if app had been running or in background, URI intent.data is not null in onNewIntent() and works fine. 但是,如果应用程序已在运行或在后台运行,则URI intent.data在onNewIntent()中不为null,并且可以正常工作。

Not sure what I am missing. 不知道我在想什么。 It's running on a Galaxy J3 Prime, Android 7.0. 它在运行Android 7.0的Galaxy J3 Prime上运行。 Here is the config. 这是配置。 Any ideas how to get intent.data URI from cold start? 任何想法如何从冷启动获取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"

Turns out this works as-is. 事实证明这是按原样进行的。 There was an exception elsewhere causing launch activity to skip updating from URI data. 在其他地方有一个例外,导致启动活动跳过了从URI数据的更新。 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: 为了追踪,我在从Android Studio的应用程序链接冷启动期间将调试器附加到设备进程,如下所示:

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. 进行API调用,并在启动活动中显示带有繁忙指示器的PopupWindow。 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 为了使弹出窗口正常工作,活动启动周期完成后,将在onCreate()中显示弹出窗口

activityRootView.post {
  handleAppLinkIntent(intent) // show busy popup and do stuff with intent.data
}

Check out this question . 看看这个问题 You should override onNewIntent and then handle data from it. 您应该重写onNewIntent,然后从中处理数据。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Intent 返回到 Xamarin android 活动有非空数据,但 Intent.Data 的结果是 null - Intent returned to Xamarin android activity has non-null Data, but the result of Intent.Data is null Android:如果从“近期任务”启动应用程序,则 Activity 使用旧意图 - Android: Activity is using old intent if launching app from Recent Task 飞艇深层链接通知正在启动没有意图数据的应用程序 - Airship deep link notification is launching app with no data in the intent 从通知意图启动活动时重新创建 Android ViewModel - Android ViewModel recreated when launching activity from notification intent 通过意图将数据从应用程序传递到小部件时,空指针 - Null Pointer When Passing Data from App to Widget via Intent ShareCompat.IntentBuilder:与收件人混合的Intent.data - ShareCompat.IntentBuilder: Intent.data mixed with recipient 从活动之外的课程中启动意图 - Launching intent from a class outside an activity 从服务意图启动已经运行的活动 - Launching already running activity from service intent 通过Intent Viewer和浏览器地址栏启动活动-什么都没有发生-仅在单击链接时 - Launching Activity via Intent Viewer and browser address bar - nothing happens - only when clicking link 从通知中的待定意图启动启动器活动 - Launching launcher activity from pending intent in notifications
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM