使用 Intent-filter 从 URL 打开 Android 应用程序不起作用 [英] Open Android app from URL using intent-filter not working

查看:52
本文介绍了使用 Intent-filter 从 URL 打开 Android 应用程序不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Android 应用,人们用它来替代网站.因此,当用户遇到网站的 URL 时,我希望让他们选择在我的应用程序中而不是在浏览器中打开 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).

我从各种来源了解到,我需要使用数据"过滤器向应用中的 Activity 添加 Intent 过滤器,该过滤器可过滤正确形式的 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/..."开头),当我单击其中任何一个时,它们只需打开在浏览器中,从来没有问过我想使用哪个应用程序.我在模拟器上以及在我的物理设备上安装应用程序后都尝试过,但没有任何效果.我在一个完全空白的新 Android 项目中尝试了这个,只是为了看看它是否可行,没有.

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.

然后我意识到该网站需要身份验证,如果您未登录,它会重定向到位于 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!

推荐答案

在你的

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

这篇关于使用 Intent-filter 从 URL 打开 Android 应用程序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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