android - Intent : URI not working in Android browser

标签 android android-intent intentfilter

所以我点击这个链接:

<a href="intent://www.google.com#Intent;scheme=http;action=android.intent.action.VIEW;end">Google</a>

(我知道这是一个愚蠢的例子,因为它可能只是 http://www.google.com ,但它说明了问题)

我从

中确定了这个 URI
Log.v(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://www.google.com")).toUri(
                    Intent.URI_INTENT_SCHEME));

我在 logcat 中看到以下内容:

08-02 08:32:34.708 I/ActivityManager(   71): Starting activity: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=http://www.google.com cmp=com.android.browser/.BrowserActivity }
08-02 08:32:34.748 E/Tab     ( 4188): onReceivedError -10 intent://www.google.com#Intent;scheme=http;action=android.intent.action.VIEW;end The protocol is not supported

我没有重定向到 www.google.com,而是看到“网页不可用”页面。

如果我使用 am 二进制文件启动相同的 Intent ,它就会成功。

adb -e shell am start -d http://www.google.com -a android.intent.action.VIEW

我在 logcat 中看到了这个

08-02 08:47:42.488 I/ActivityManager(   71): Starting activity: Intent { act=android.intent.action.VIEW dat=http://www.google.com flg=0x10000000 cmp=com.android.browser/.BrowserActivity }

最终目标是拥有一个在应用程序中启动特定 Activity 的 URL(没有安装应用程序的人无法访问此页面)。我知道我也可以定义一个自定义方案,但由于它是一个全局命名空间,我不想那样做。我也知道我可以为此目的使用 http://,但我不想提示用户是想在浏览器中还是在我的应用程序中打开 URL。

有什么想法吗?

最佳答案

我遇到了同样的问题

将以下代码添加到我在 AndroidManifest.xml 中的 Activity 解决了我的问题:

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

关于android - Intent : URI not working in Android browser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8031790/

相关文章:

android - ResultReceiver 无法幸免于屏幕旋转

android - 我如何在android studio上看到xml Drawerlayout文件

android - Uri 中的 "Shadow"和 "high"字符串直接重定向到 Android 中的浏览器

android - 无法从深层链接获取 Uri 数据

java - gdx-支付 : "package com.badlogic.gdx.pay does not exist"

android - 为什么建议不要对 Android 房间使用 allowMainThreadQueries()?

android - 使用cordova将android图库中的图片分享到cordova应用程序

android - 通知状态栏的 Activity Intent ?

android - 使用默认调用应用程序在 Android 应用程序中进行调用

android - 深层链接启动应用程序但说 uri 为空