在更新SDK版本23后,为Android添加至少一个具有ACTION-VIEW意图过滤器的Activity

313
我在AndroidManifest.xml中收到以下工具提示:
应用程序无法被Google搜索索引;请考虑添加至少一个具有ACTION-VIEW意图填充器的活动。请参见问题说明获取更多详细信息。
添加深度链接以将您的应用程序放入Google索引中, 从Google搜索获得应用程序的安装和流量。

enter image description here

有人能解释一下为什么吗?


要查看其实际效果,请参见此处:https://dev59.com/urTma4cB1Zd3GeqP8IvA#56668348?noredirect=1#comment99925280_56668348 - user1506104
5个回答

243

根据官方文档:

为了让Google能够爬取你的应用程序内容,并允许用户通过搜索结果进入你的应用程序,你必须在应用程序清单中为相关活动添加意图过滤器。这些意图过滤器允许深层链接到任何活动中的内容。例如,用户可能会点击一个深度链接,以查看描述他正在搜索的产品提供的购物应用程序中的页面。

你可以使用此链接Enabling Deep Links for App Content了解如何使用它。

并使用此链接Test Your App Indexing Implementation来测试它。

以下 XML 片段显示了如何在清单中为深度链接指定意图过滤器。

<activity
    android:name="com.example.android.GizmosActivity"
    android:label="@string/title_gizmos" >
    <intent-filter android:label="@string/filter_title_viewgizmos">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
        <data android:scheme="http"
              android:host="www.example.com"
              android:pathPrefix="/gizmos" />
        <!-- note that the leading "/" is required for pathPrefix-->
        <!-- Accepts URIs that begin with "example://gizmos” -->
        <data android:scheme="example"
              android:host="gizmos" />

    </intent-filter>
</activity>

通过Android调试桥测试

$ adb shell am start
        -W -a android.intent.action.VIEW
        -d <URI> <PACKAGE>

$ adb shell am start
        -W -a android.intent.action.VIEW
        -d "example://gizmos" com.example.android

5
@user25 中的 scheme 是 URI 方案,方案可以是 http、https、ftp 等。 - Bhargav
89
这些都是针对特定应用程序的,那么为什么还要显示这个警告?并不是所有应用程序都需要这个,也不是所有应用程序都是某些网站的Webview。谷歌真是太烦人了... - user924
64
可以使用 tools:ignore="GoogleAppIndexingWarning" 工具来抑制警告。 - ecle
12
有趣的是这个警告说需要一个ACTION-VIEW的intent-filter,但解决方案涉及到action.VIEW。同样地,在Android Studio中跟随链接会带你进入一个没有出现ACTION-VIEW的网页。至少他们在显眼的警告中应该给出准确的信息和帮助页面。 - John Perry
7
这个选项应该放在哪里?/ 没关系,我找到了:你需要在manifest标签中添加xmlns:tools="http://schemas.android.com/tools",然后在application标签中添加tools:ignore... - John Perry
显示剩余3条评论

198
您可以通过在<activity>内部的<intent-filter>中添加以下代码来删除警告。
<action android:name="android.intent.action.VIEW" />

6
这份工作适合我。我认为这就是我正在寻找的答案。 - Mahmudur Rahman
13
如果您不想启用应用索引,则这似乎是正确的解决方案。与其仅通过tools:ignore="GoogleAppIndexingWarning"移除警告,我在主活动中将其作为<action android:name="android.intent.action.MAIN" />的同级添加。 - Daniel F
4
为什么我们需要盲目地在代码中加入这行?有具体的原因吗? - GS Nayma
2
@Ghanshyam,这是关于在谷歌搜索中进行应用索引的内容。也就是说,这可以使您的应用程序显示在谷歌搜索结果中。 - Bibin Johny
15
@GhanshyamNayma添加这行代码只是为了消除警告,但没有添加实际的应用索引所需的额外代码。这并不是最佳实践,但我知道警告很烦人。我建议只使用tools:ignore="GoogleAppIndexingWarning",因为这样就不会添加一个空ACTION_VIEW。它可能不会引起任何问题,但你始终希望保持安全。 - Carson J.
8
啊,这就是为什么现在会有那么多随机的应用程序出现在 ACTION_VIEW 中的原因... 唉。 - CCJ

138
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.app"
tools:ignore="GoogleAppIndexingWarning">

您可以通过在 <manifest> 标签中添加 xmlns:tools="http://schemas.android.com/tools"tools:ignore="GoogleAppIndexingWarning" 来移除此警告。


3
这对我很有效,也正是我在寻找的解决方案。 - Sayan Sil
这是完美的解决方案。 - Rudra
5
这并不是完美的解决方案,因为它不允许谷歌索引应用程序。通过忽略某些事情,您应该尝试克服这个问题。 - Pratik Butani
@PratikButaniAndroidDev 在应用商店中进行索引并不是许多开发者的首要任务,尤其是在开始开发应用程序时。 - Maher Abuthraa

25

我在应用程序清单中声明的一个活动中添加了此意图过滤器,这为我解决了问题。

<activity
    android:name=".MyActivity"
    android:screenOrientation="portrait"
    android:label="@string/app_name">

    <intent-filter>

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

    </intent-filter>

</activity>

我有这个,但是使用了intent.action.MAIN,它没有消失。 - C. Skjerdal
你需要确保它设置为 android.intent.action.VIEW。 - Oladipo Olasemo

1

这个解决方法仅适用于您希望忽略此警告的情况。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="GoogleAppIndexingWarning"
    package="com.example.saloononlinesolution">

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接