从深层链接的意图中获取空值

编程入门 行业动态 更新时间:2024-10-05 07:19:28
本文介绍了从深层链接的意图中获取空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我向我的应用程序添加了一个深层链接,该链接将活动映射到我网站上的特定网页(链接称为: developer.android/training/app-links/deep-linking )。 在处理Java代码中的深层链接时, getAction()和 getData()方法给我空值。 我尝试在此处进行测试: firebase.google / docs / app-indexing / android / test (这给了我完美的结果),但单击该链接时,它会在Web浏览器中而不是在我的应用程序中打开。

I have added a deep link to my app which maps an activity to a particular web page on my website (Link referred: developer.android/training/app-links/deep-linking ). While handling the deep link in my Java code, getAction() and getData() methods give me null value. I tried testing it here: firebase.google/docs/app-indexing/android/test (This gave me perfect result) But the same link opens in A web browser rather than in my app when clicked.

Android清单代码:

Android Manifest code :

<activity android:name=".MainActivity" android:screenOrientation="portrait" android:launchMode="singleTask" android:exported="true"> <tools:validation testUrl="www.mywebsite/xyz" /> <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="www.mywebsite" android:pathPrefix="/xyz" /> </intent-filter> </activity>

Java代码:

Intent intent = getIntent(); String action = intent.getAction(); // getting null value here Uri data = intent.getData(); // getting null value here

我希望如果该应用存在,则应在打开应用时打开单击该链接,否则该链接将打开网页。 我在哪里和想念什么?

I want that if the app is present, then it should be opened when the link is clicked or else the link will open the web page. Where and what am I missing?

推荐答案

您可能会遇到此问题,因为使用 singleTask 。在这种情况下,您应该使用 onNewIntent 更新意图,因为 onCreate 和 onResume 不会处理它。

You can run into this problem because using singleTask. In that case you should use onNewIntent to 'update' intent, because onCreate and onResume will not handle it.

在其包中将launchMode设置为 singleTop的活动,或者如果客户端在调用startActivity(Intent)时使用了Intent#FLAG_ACTIVITY_SINGLE_TOP标志,则调用此方法。在这两种情况下,当在活动堆栈的顶部重新启动活动而不是启动活动的新实例时,将使用已用于重新启动的Intent在现有实例上调用onNewIntent()

This is called for activities that set launchMode to "singleTop" in their package, or if a client used the Intent#FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent). In either case, when the activity is re-launched while at the top of the activity stack instead of a new instance of the activity being started, onNewIntent() will be called on the existing instance with the Intent that was used to re-launch it.

override fun onNewIntent(intent: Intent?) { super.onNewIntent(intent) //TODO: do something with new intent }

更多推荐

从深层链接的意图中获取空值

本文发布于:2023-11-28 03:27:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意图   链接

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!