从URL使用意向过滤器打开Android应用程序无法正常工作 [英] Open Android app from URL using intent-filter not working

查看:345
本文介绍了从URL使用意向过滤器打开Android应用程序无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序的人作为替代品的网站上使用。因此,当用户遇到一个网址的网站,我想给他们在我的应用程序,而不是在浏览器中打开URL选项。换句话说,我希望出现的弹出让他们我的应用程序和浏览器(以及可能的其他应用程序)之间进行选择。

I have an Android app that people use as a replacement for a website. Hence, when users encounter an URL to the website, I want to give them the option to "open the URL" in my app instead of in the browser. In other words I want the popup to appear that lets them choose between my app and the browser (and possibly other apps).

我的,我需要添加一个意图过滤器,以活动在我的应用程序的数据过滤器的正确形式的URL过滤各种渠道了解。

I understand from various sources that I need to add an intent filter to an activity in my app with the 'data' filter that filters on URLs of the correct form.

有问题的网站是 http://members.iracing.com ,所以我加入了以下意图过滤器:

The website in question is http://members.iracing.com, hence I have added the following intent filter:

    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <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" />
            <data android:scheme="http" />
            <data android:host="members.iracing.com" />
        </intent-filter>
    </activity>

我曾尝试过各种形式的这些数据过滤器,就像使用一个单一的数据节点,这两个属性:

I have tried various forms of these data filters, like using a single 'data' node with both attributes:

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="http" android:host="members.iracing.com"/>
        </intent-filter>

这是根本无法工作。我不知道还有什么要告诉你。我托管在我的网站上简单的HTML页面有几个链接到不同的页面上的网站(全部是以http://members.iracing.com / ......),当我点击其中任何一个,他们只需打开在没有以往任何时候都问我,我想要使用的应用程序的浏览器。我试了一下两者的仿真器,以及我的物理设备上安装应用程序后,没有什么作品。我在一个完全空白的,新的Andr​​oid项目尝试这样做只是为了看看是否能够正常工作,什么都没有。

It is simply not working. I don't know what else to tell you. I hosted a simple HTML page on my website with a couple links to various pages on that website (all starting with "http://members.iracing.com/...") and when I click any of them, they simply open in the browser without ever asking me which app I want to use. I tried it both on the emulator as well as after installing the app on my physical device, nothing works. I tried this in a completely BLANK, new Android project just to see if that would work, nothing.

我才明白,该网站需要身份验证,如果您还没有登录它重定向到登录页面,在<一个href="https://members.iracing.com/membersite/login.jsp">https://members.iracing.com/membersite/login.jsp,因此,我试图通过https开头替换方案。我甚至试图改变主机www.members.iracing.com,并在最后我甚至尝试了所有这些东西的组合(不知道这应该工作,但是,嘿,我拼命在这一点.. ...)

I then realized that the website requires authentication, and if you are not logged in it redirects to the login page at https://members.iracing.com/membersite/login.jsp, hence I tried replacing the scheme by "https". I even tried changing the host to "www.members.iracing.com", and in the end I even tried a combination of all these things (not sure if this should work, but hey, I'm desperate at this point.....)

       <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="http" />
            <data android:scheme="https" />
            <data android:host="members.iracing.com" />
            <data android:host="www.members.iracing.com" />
        </intent-filter>

仍然没有去。我不知道如果重定向是相关的,虽然,在浏览器显然第一次进入到非定向的网站,然后进行重新定向到登录页面,但在任何时候,我得到的选择在我的应用程序中打开它。此外,如果我在浏览器中第一次手动登录,没有重定向,它仍然无法正常工作。

Still no go. I'm not sure if the redirect is relevant though, the browser clearly first goes to the non-redirected site, then does the redirect to the login page, but at no point do I get the choice to open it in my app. Furthermore, if I login manually in the browser first, there is no redirect, and it still does not work.

我在这里丢失了一些东西明显?我拉我的头发,这是为什么不工作了,我可以把它除了尝试各种可能的组合我能想到的不是调试(我... ...)。感谢您的帮助!

Am I missing something obvious here? I'm pulling my hair out why this isn't working, and I cannot debug it besides trying every possible combination I could think of (I did...). Thanks for any help!

推荐答案

在使用这三种你的&LT;意向滤光器&gt;

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

这篇关于从URL使用意向过滤器打开Android应用程序无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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