【问题标题】:Android 4.0 launching app from url not workingAndroid 4.0 从 url 启动应用程序不起作用
【发布时间】:2012-08-09 15:22:12
【问题描述】:

我遇到了一个奇怪的问题,即启动我的应用程序而不是 url,而是将应用程序加载到浏览器本身,在本例中是 mozella!

这是我用于我的应用程序的意图过滤器,如果有人可以告诉我我做错了什么。

<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
    android:name=".Globals"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".RSS_ViewerActivity"
        android:label="@string/app_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" />
               <data android:scheme="itpc" />
               <data android:scheme="pcast" />
               <data android:scheme="feed" />
               <data android:scheme="feeds" />
               <data android:scheme="rss" />
        </intent-filter>

        <intent-filter>
               <action android:name="android.intent.action.VIEW" />
               <category android:name="android.intent.category.DEFAULT" />
               <data android:mimeType="text/xml" android:scheme="http" />
               <data android:mimeType="application/rss+xml" android:scheme="http" />
               <data android:mimeType="application/atom+xml" android:scheme="http" />
               <data android:mimeType="text/xml" android:scheme="https" />
               <data android:mimeType="application/rss+xml" android:scheme="https" />
               <data android:mimeType="application/atom+xml" android:scheme="https" />
        </intent-filter>

    </activity>
    <activity android:name="RSSFeedActivity"></activity>
    <activity android:name="com.CertificateAuthentication.Authenticator"></activity>
</application>

谢谢。

更新

再多一点信息,当弹出要求选择和应用程序打开链接的对话框时,它不会显示我的应用程序,或任何与此相关的内容。

更新

我删除了第二个和第三个意图过滤器,我尝试将剩余的 2 个意图过滤器合并为 1 个,但这不会从浏览器加载应用程序。上面的代码是现在的样子,得到的结果和以前一样 =( 这很烦人,因为这意味着用户可以运行 2 个应用程序会话,一个来自浏览器,一个来自启动器。

【问题讨论】:

    标签: android android-intent android-browser


    【解决方案1】:

    您的第二个和第三个 &lt;intent-filter&gt; 元素可能不起作用,因为 android:host 没有记录支持通配符。

    【讨论】:

    • 干杯,但不幸的是没有工作=(我试图将操作更改为主要,但这不起作用,因为要求选择应用程序的对话框从未显示我的应用程序!!跨度>
    【解决方案2】:

    这里的问题是\。这是转义字符,所以要使这个表达式工作你需要\\Documentation clearly says 表示您需要使用\\. 表示点(有\\* 的示例)。

    我也同意 CommonsWare 的回答,我在documentation 中找到了这样的说法:

    这些属性中的每一个都是可选的,但它们并不独立于 彼此:要使权威有意义,还必须有计划 指定的。为了一条有意义的路径,一个计划和一个权威 必须指定。

    The host and port together constitute the URI authority 所以在实践中,权威意味着主机,所以你不能省略它,显然你不能在那里放一颗星。

    IMO 你让它变得复杂,你不需要在这里定义路径!哑剧类型应该可以完成这项工作。尝试找到一些读取 RSS 的开源项目,看看它们是如何定义清单的。

    我认为你需要这样的东西:

    <activity
        android:name=".RSS_ViewerActivity"
        android:label="@string/app_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.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="itpc" />
            <data android:scheme="pcast" />
            <data android:scheme="feed" />
            <data android:scheme="feeds" />
            <data android:scheme="rss" />
            <data android:mimeType="text/xml" android:scheme="http" />
            <data android:mimeType="application/rss+xml" android:scheme="http" />
            <data android:mimeType="application/atom+xml" android:scheme="http" />
            <data android:mimeType="text/xml" android:scheme="https" />
            <data android:mimeType="application/rss+xml" android:scheme="https" />
            <data android:mimeType="application/atom+xml" android:scheme="https" />
        </intent-filter>
    
    </activity>
    

    【讨论】:

    • 感谢您的帮助,我按照您和 commonsware 的建议取出了这 2 个意图过滤器,我已经更新了上面的帖子。虽然我仍然得到相同的结果=(我也从另一个浏览器尝试过,股票的 android 浏览器,我得到相同的结果是从浏览器查看应用程序,而不是启动/恢复,如果它正在运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    • 1970-01-01
    • 2015-02-12
    相关资源
    最近更新 更多