我有一个应用程序,我需要在不同的启动类型上做不同的任务。当我的应用程序在后台时,如何检测到应用程序已被deeplink启动。
发布于 2020-02-03 21:10:23
假设您已经准备好了一个具有所需意图的活动,您要做的是检查您的活动的if(getIntent().getAction() != null),这意味着它是通过一个深度链接启动的。用于导航的普通意图将返回null。
现在的问题是,如果您的活动已经在后台运行,并且您在onCreate()中编写了此代码,并且深度链接的活动被设置为android:launchMode="singleTask"或使用FLAG_ACTIVITY_SINGLE_TOP启动,它将不会再次触发。
为此,你必须覆盖你的活动的onNewIntent(Intent intent)方法,这样你就可以知道每次你的活动是从意图开始的。同样,在这里您可以检查if(intent.getAction() != null)和intent.getData()以检索数据。
需要注意的一点是,避免在onCreate和onNewIntent中重复运行相同的代码
如果您还没有在您的应用程序中实现深度链接,则首先需要使用<intent-filter>来使activity可用于处理单击链接时的意图,例如
<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:host="www.example.com"
android:pathPattern="/.*"
android:scheme="https" />
</intent-filter>你可以在官方文档here上阅读更多关于有人已经建议的内容。
发布于 2020-02-03 19:55:22
当点击的链接或编程请求调用web URI意图时,Android系统将按顺序尝试以下每个操作,直到请求成功:
打开可以处理URI的用户首选应用程序(如果已指定)。打开唯一可以处理URI的可用应用程序。允许用户从对话框中选择应用程序。
要创建指向应用程序内容的链接,请在清单中添加包含以下元素和属性值的意图筛选器:
https://developer.android.com/training/app-links/deep-linking
查看android官方文档了解更多关于deeplinking的信息
发布于 2020-11-29 21:13:15
在MainActivity中,我使用以下代码
if(getIntent().getDataString()!=null &&
getIntent().getDataString().contains("specialWordInDeepLink")){
// confirm is run by deeplink
}https://stackoverflow.com/questions/60038667
复制相似问题