从启动Android浏览器/浏览器定制的Andr​​oid应用 [英] Launching custom Android application from Android browser / Chrome

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

问题描述

首先,我的问题是非常相似的<一href="http://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser">this, 和的这个。 Android的文档,我想要实现的是这里。我不能让这个使用这些资源,所以请不要标明这是重复的,因为它是不工作。

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.

我有一个网站和一个Android应用程序。用户将能够扫描QR codeS包含如 http://mywebsite.com/map/ 链接。当用户试图打开这个链接,我想机器人给他一个选择对话框,在那里他可以选择使用我的应用程序打开该链接。如果我不安装应用程序,它应该进入到指定的网页。

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.

我知道Chrome浏览器可以通过打开的选择对话框,当用户导航到该地址。例如,尝试下载堆叠交换应用,并打算对这个问题的Chrome浏览器。它会显示这样的:

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:

我添加了以下code在AndroidManifest.xml中按照上述答案的建议后:

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>

另外,我还尝试添加机器人:MIMETYPE =text / plain的数据,但它并没有帮助

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

的问题是,当我去 http://mywebsite.com/map 或的 http://mywebsite.com/map/ Chrome浏览器只是打开网页而不显示选择对话框

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.

我想提的:

  • 继Android的文档,我加入了里面的活性结构在AndroidManifest.xml中的一个这个code。由于我不知道这是增加它的完美的地方,我也尝试添加它以外的应用结构和应用结构直接内,但没有奏效
  • 这是唯一的code我已经实现了这个工作。如果别的东西是必要的,请让我知道。据我了解,增加A HREF的网页只使用自定义模式时,需要
  • 我不希望使用自定义模式,以实现这一点
  • 在我开发上的Nexus 4,运行Android 4.4.2(最新)

推荐答案

您需要设置它是这样的:

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>

请注意,你的情况,你将需要使用的Andr​​oid版本:路径preFIX,而不是机器人:路径

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

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

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