【问题标题】:Android 8.0+ Deep Linking Opens Launcher Activity First Only When App was KilledAndroid 8.0+ 深度链接仅在应用程序被杀死时才首先打开启动器活动
【发布时间】:2019-12-13 04:29:58
【问题描述】:

仅在 Android 8.0+ 上,当打开我的带有深层链接的应用时(单击带有 URI 的推送通知),该应用将打开我的入口点活动,然后打开深层链接活动。

这在低于 8.0 的 Android 上看不到。在这种情况下,它会直接打开深层链接活动,而不会打开闪屏活动。

不幸的是,应用程序的工作方式是,当调用入口点活动(它是一个启动屏幕)时,它会移动到另一个活动。这使得在应用程序硬关闭时打开深层链接非常不可靠,因为当深层链接活动运行时(启动屏幕运行后大约 80 毫秒),应用程序已经过渡到下一个活动,这可能会完全取消深层链接。

为了避免这种情况,我尝试通过将launchMode 设置为singleTask、singleTop 和singleInstance 来处理splash 活动内部的深层链接。不幸的是,这些都不起作用。

我已经设法通过使用计时器解决了这个问题,方法是让启动屏幕比平时长 200 毫秒,但该解决方案似乎很脏,而且似乎对所有设备都不是非常可靠。

这是我的启动活动和清单中的深层链接活动

<activity
 android:name=".activities.LauncherActivity"
 android:excludeFromRecents="true"
 android:taskAffinity="${launcherAffinity}"
 android:theme="@android:style/Theme.Translucent.NoTitleBar">
 <intent-filter>
    <action android:name="android.intent.action.MAIN" />

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


<activity
 android:name=".activities.ParseDeepLinkActivity"
 android:theme="@android:style/Theme.NoDisplay">
 <intent-filter>
  <action android:name="android.intent.action.VIEW" />

   <data
     android:host="*"
     android:scheme="com.deeplink" />

     <category android:name="android.intent.category.DEFAULT" />
     <category android:name="android.intent.category.BROWSABLE" />
  </intent-filter>
  <intent-filter>
   <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="deep.link.net"
         android:pathPrefix="/mobile" />
  </intent-filter>
</activity>

这是我的启动器活动

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launcher);
        startActivity(
                new Intent(this, LoginActivity.class)
                        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        finish();
    }

如果我可以直接打开深层链接活动,就像它在低于 8.0 时所做的那样,我希望它。如果深度链接在 8.0+ 中发生了变化,我尝试搜索任何文档,但我找不到任何东西。

【问题讨论】:

    标签: android deep-linking urbanairship.com


    【解决方案1】:

    解决了!

    问题出在 UrbanAirship 中。我们在 onNotifactionOpened 方法中扩展 AirshipReceiver 的类默认返回 false,这意味着它也会启动启动器活动。为什么这只会在 8.0+ 中引起问题,我不太确定。这是我的解决方法

     @Override
        protected boolean onNotificationOpened(@NonNull Context context, @NonNull NotificationInfo notificationInfo) {
            Map<String, ActionValue> notificationActions = notificationInfo.getMessage().getActions();
            // Return false here to allow Urban Airship to auto launch the launcher activity
            try{
                return notificationActions.containsKey("^d");
            }catch(Exception e){
                return false;
            }
        }
    

    ^d 是此处列出的深层链接操作的默认键 https://docs.airship.com/reference/libraries/android/latest/reference/com/urbanairship/actions/DeepLinkAction.html

    【讨论】:

    • 您好 Napkins 先生,您也可以分享您的接收器的代码吗?谢谢你,祝你有美好的一天!
    猜你喜欢
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    相关资源
    最近更新 更多