jjzjj

android - Intent 过滤器 : Using two actions along with Launcher and Browsable category

coder 2023-12-26 原文

TL;DR 我可以在一个 intent-filter 中使用两个 Action 和两个类别吗?

我的应用由一个 Activity 和五个 Fragment 组成。我在此 Activity 中有一个 Intent 过滤器。

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

今天,我在 list 文件中的 application 标签周围看到一条 lint 消息“Google 无法索引应用程序...”。因此,我进行了一些搜索,了解到您可以使用它通过谷歌搜索为您的应用编制索引。如果 android 用户从 chrome/systemBrowser 浏览网页链接“www.example.com/myapp”,他将被带到我的应用程序而不是网页。对吧?

现在,我必须向 Activity 添加一个 ActionView。而且,我的 Intent 过滤器将变成,

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.LAUNCHER" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http" android:host="www.example.com" android:pathPrefix="/myapp" />
 </intent-filter>

但是,我读到使用两个 Action 并不好。这是一个逻辑或操作。 Intent-Filter 将只匹配其中一个:

    1. 具有 MAIN 操作和 LAUNCHER 类别的 Intent
    1. 具有 MAIN 操作和 BROWSABLE 类别的 Intent
    1. 具有 VIEW 操作和 LAUNCHER 类别的 Intent
    1. 具有 VIEW 操作和 BROWSABLE 类别的 Intent

据我了解,它应该使用第一个选项在设备上打开应用程序,当用户浏览提供的“www.example.com/myapp”的浏览器时,它应该使用第一个和第四个选项从链接打开应用程序.

我看过这个question ,但我需要用一个例子来确定。

令人困惑。我可能完全错了,请指导我。

最佳答案

在 SO Chat 某人的帮助下,我被告知要使用单独的 intent-filters

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

    </activity>

关于android - Intent 过滤器 : Using two actions along with Launcher and Browsable category,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40617369/

有关android - Intent 过滤器 : Using two actions along with Launcher and Browsable category的更多相关文章

随机推荐