Android:过滤特定 Uri 模式的意图
我需要我的 Android 应用程序在我的应用程序中运行某个 Activity,响应发送出去的 Intent 中的以下 Uri 数据:
如果我在清单中使用以下内容(对于我想要响应 Intent 的 Activity),我可以捕获它,但是弹出选择器(我不想要):
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" android:host="www.example.com" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
由于我不希望弹出选择器,因此我尝试在标签中使用 android:pathPattern 或 android:pathPrefix 来进一步过滤,以确保只有我的应用程序响应,但它对我不起作用。
谁能帮我做这个吗?
I need my Android application to run a certain Activity in my app, responding to the following Uri data from the Intent that was sent out:
If I use the following in my manifest (for the Activity that I want to respond to the Intent), I can capture this, but the chooser pops up (which I don't want):
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" android:host="www.example.com" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Since I don't want the chooser to pop up, I tried to use the android:pathPattern, or android:pathPrefix in the tag to further filter to make sure that only my app responds but it isn't working for me.
Can anyone help me do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大多数 Android 设备上都会有 1 个以上的浏览器他们。完全欢迎用户在这些浏览器之一而不是您的应用程序中访问该 URL,这就是选择器出现的原因。此外,如果开发人员能够劫持他们想要的任何 HTTP URL,这将是一个巨大的安全漏洞。
现在,如果您拥有此 URL 链接到的网站,则可以使用条形码扫描仪使用的技巧:使用浏览器检测在该页面上放置智能信息,如果在 Android 浏览器中查看,则会向用户解释为什么他们应该这样做允许您的应用程序将来处理该 URL。
Most Android devices will have 1+ browsers on them. The user is perfectly welcome to visit that URL in one of those browsers instead of your app, which is why the chooser appears. Moreover, it would be a massive security hole if developers were able to hijack any HTTP URL they wanted.
Now, if you own the Web site for which this URL links to, you can use the trick that Barcode Scanner uses: use browser detection to put smarts on that page that, if viewed in an Android browser, explains to the user why they should allow your app to handle that URL in the future.
它看起来就像您处理来自您自己的应用程序的数据,因此不要使用您的“私有”URL 作为意图的目标,而是创建一个特定于组件的意图并将其数据的 URL 作为额外参数。
类似于:
在 yourActivity.class 中,您只需使用以下代码获取 Uri:
It looks like your dealing with data which comes from your own application, so don't use your "private" URL as the target of the intent but create a component specific Intent and give it the URL of your data as an EXTRA parameter.
Something like:
In yourActivity.class, you would just have to get the Uri with the following code: