从 Android 浏览器/Chrome 启动自定义 Android 应用程序 [英] Launching custom Android application from Android browser / Chrome

查看:20
本文介绍了从 Android 浏览器/Chrome 启动自定义 Android 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我的问题非常类似于 或 http://mywebsite.com/map/ Chrome 浏览器只打开网页而不显示选择器对话框.

我想提一下:

  • 按照 Android 文档,我在 AndroidManifest.xml 的活动结构之一中添加了此代码.由于我不确定这是添加它的最佳位置,因此我也尝试将其添加到应用程序结构之外并直接添加到应用程序结构内,但没有成功
  • 这是我为此实现的唯一代码.如果需要其他东西,请告诉我.据我了解,只有在使用自定义架构时才需要向网页添加 href
  • 我不想使用自定义架构来实现这一点
  • 我正在 Nexus 4 上开发,运行 Android 4.4.2(最新)

解决方案

你需要这样设置:

<action android:name="android.intent.action.VIEW"/><category android:name="android.intent.category.DEFAULT"/><category android:name="android.intent.category.BROWSABLE"/><数据机器人:主机=example.com"android:pathPrefix="/someresource/"android:scheme="http"/><数据android:host="www.example.com"android:pathPrefix="/someresource/"android:scheme="http"/></意图过滤器>

请注意,在您的情况下,您需要使用 android:pathPrefix 而不是 android:path.

First of all, my question is extremely similar to this, this and this. The Android documentation for what I'm trying to achieve is here. I couldn't get this to work using these resources so please don't mark this as duplicate as it is not.

I have a website and an Android application. The user will be able to scan QR codes that contain links like http://mywebsite.com/map/. When the user tries to open this link, I want Android to show him a chooser dialog where he can choose to open that link using my application. If my application is not installed, it should proceed to the specified website.

I know Chrome allows this by opening the chooser dialog when the user navigates to that address. For example, try downloading the Stack Exchange app and going to this question in Chrome. It will show this:

I have added the following code in AndroidManifest.xml after following the suggestion in the above-mentioned answers:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.intent.action.SEND" />

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

    <data
        android:host="mywebsite.com"
        android:path="/map"
        android:scheme="http" />
    <data
        android:host="mywebsite.com"
        android:path="/animals"
        android:scheme="http" />
    <data
        android:host="mywebsite.com"
        android:path="/articles"
        android:scheme="http" />
</intent-filter>

Also, I have tried adding android:mimeType="text/plain" to data but it didn't help.

The problem is that when I go to http://mywebsite.com/map or http://mywebsite.com/map/ Chrome just opens the webpage without showing the chooser dialog.

I would like to mention:

  • following the Android documentation, I have added this code inside one of the activity structures in AndroidManifest.xml. As I am not sure this is the perfect place to add it, I have also tried adding it outside the application structure and directly inside the application structure but it didn't work
  • this is the only code I have implemented for this to work. If something else is needed please let me know. From what I understand, adding a href to the webpage is only needed when using custom schemas
  • I do not want to use a custom schema in order to achieve this
  • I am developing on a Nexus 4, running Android 4.4.2 (latest)

解决方案

You need to set it up like this :

<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="example.com"
            android:pathPrefix="/someresource/"
            android:scheme="http" />
        <data
            android:host="www.example.com"
            android:pathPrefix="/someresource/"
            android:scheme="http" />
    </intent-filter>

Notice that in your case, you would need to use android:pathPrefix instead of android:path.

这篇关于从 Android 浏览器/Chrome 启动自定义 Android 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆