Android 网址覆盖不适用于重定向

标签 android android-intent intentfilter url-scheme

我有一个在我的 Android 应用程序中覆盖的 url。单击电子邮件中指向该链接的链接会弹出 Intent Chooser对话框(“完成此使用”)。但是,从 Chrome(在 Android 4 上)中单击相同的链接(在 <a> 标记中)会将我重定向到该 url,并且不提供 Intent Chooser .

如果我替换 <a> 中的链接带有 Google Play 商店链接的标签 (https://play.google.com),然后单击该链接会弹出 Intent Chooser再次。

Google Play 商店和 Chrome 有什么特别之处,还是我在配置网址时做错了什么?我可以在 html 中做些什么来完成这项工作吗?

这是 <intent-filter>

<activity
    android:label="@string/app_name"
    android:name="..."
    >
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </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="www.example.com"
            />
        <data android:scheme="http"
              android:host="www.example.com"
            />
    </intent-filter>
</activity>

(重定向到 url 也不会弹出 Intent Chooser 对话框,但我认为我上面的情况更尖锐地表达了我的问题。)

另外值得注意的是,我相当确定这一切在我的域关闭时都能正常工作。我的域一上线,它就停止工作了。这可能是我的想象,因为当时我并没有 100% 专注于这个问题。

Chrome 是否有可能将 Google Play 商店网址特殊对待,否则它会在打开 Intent Chooser 之前等待来自网址的非 200 响应?

最佳答案

我对此进行了相当多的修改,向您展示一种有效的方法可能会更容易。这适用于 2.3.4 的设备和 4.2.2 的设备,所以我认为它适用于大多数设备。

这是来自 list 文件的我的 Intent 过滤器:

<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="http" android:host="realsimpleapps.com" android:pathPrefix="/acv/" />
</intent-filter>

这是我的 html 文件:

<a href="http://realsimpleapps.com/acv/aThing">Click Me!</a>

在我的主要 Activity 中,我使用它来获取我将“aThing”(上图)设置为的任何内容:

Uri data = getIntent().getData();
if (data != null) {
    List<String> params = data.getPathSegments();
    if (params != null) {
        Log.d(tag, "Param 0: " + params.get(0));
    }
}

让它工作,然后将第二个数据元素添加到 Intent 过滤器。如果在那之后它仍然有效,你应该设置。

让我们知道进展如何。

分贝

关于Android 网址覆盖不适用于重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15501990/

相关文章:

android - 接收器应用程序 - 处理 Intent 过滤器 URI 的权限

java - APK 未从下载文件夹中删除

java - 从 getActionProvider() 设置 ShareActionProvider 时如何解决 Null 问题?

android - intent-filter不去Android系统

android - ksoap2 类型转换 getResponse()

android - Nexus S 和三星 Galaxy S I9000 上的 ACTION_IMAGE_CAPTURE 方向问题

android - 为不同的 Activity 处理相同的 Intent 过滤器

android - 使用命令行linux安装android sdk

android - 生成的音频正弦波的持续时间

android - 重新安装应用程序后有时无法释放相机