【问题标题】:Integrating the app with Google search results and Chrome将应用程序与 Google 搜索结果和 Chrome 集成
【发布时间】:2014-07-29 08:02:38
【问题描述】:

官方的 Wikipedia 应用程序以某种方式做到了这一点,在我的应用程序中,我使用标准意图过滤器来监听导航到 Wikipedia url。

有没有办法与 Google 搜索集成?是否有任何 API 可用,还是仅对选定的 API 可用?

【问题讨论】:

  • 你看到我的回答有什么问题吗?

标签: android android-intent google-chrome-app intentfilter google-search


【解决方案1】:

根据the documentation,您必须将元标记添加到您希望搜索显示应用程序链接的页面。例如,在您的屏幕截图的搜索结果中链接的 Wikipedia 页面的源代码中包含以下链接:

<link rel="alternate" href="android-app://org.wikipedia/http/en.m.wikipedia.org/wiki/Apollo_17" />

我假设您无法通过其他方式将指向您的应用的链接添加到搜索结果:搜索结果还建议用户安装他们尚未安装的应用。赋予决定向页面所有者以外的人推荐哪个应用程序的权力显然是危险的。另一个强有力的提示是文档没有提到任何替代方案。

【讨论】:

    【解决方案2】:

    我没记错,谷歌在今年的谷歌 I/O 大会上宣布,Android L 将提供实现这一目标的 API

    可以在 33:45 的 keynote video 中找到该公告,尽管它没有说明它将如何工作

    【讨论】:

      【解决方案3】:

      您需要在网页的 HTML 标记中注释深层链接。您可以在每个网页的部分中通过添加标记并将深层链接指定为备用 URI 来执行此操作。

      参见 Wikipedia 示例(我查找了您搜索的内容的页面来源)

      <meta name="generator" content="MediaWiki 1.24wmf15" />
      <link rel="alternate"
        href="android-app://org.wikipedia/http/en.m.wikipedia.org/wiki/Apollo_17" />
      <link rel="alternate" 
        type="application/x-wiki" title="Edit this page" href="/w/index.php?  title=Apollo_17&amp;action=edit" />
      

      您需要将以下代码添加到您的网页:

      <html>
      <head>
          <link rel="alternate"
            href="android-app://com.example.android/example/gizmos" />
      ...
      </head>
      <body> ... </body>
      

      现在要在应用程序中处理此意图,当您搜索某些内容时,该链接也为您提供了在维基百科应用程序中打开的选项,如果您想同时支持这两者,那么您需要修改您的 android 应用程序.

      首先,您需要在 Manifest 中添加方案。

      这是维基百科应用程序的工作原理。

      WikiPedia 应用程序在他们的页面查看活动中添加了该方案,如下所示。

      <activity android:name=".page.PageActivity" >
      <intent-filter>
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
       <data
          android:scheme="http"
          android:host="*.wikipedia.org"
          android:pathPrefix="/wiki/" />
      <data
          android:scheme="https"
          android:host="*.wikipedia.org"
          android:pathPrefix="/wiki/" />
      </intent-filter>
      </activity>
      

      您需要为您的域做同样的事情,它会起作用。如果您需要确保您的应用程序也显示在深层链接中,请参考 link1link2

      【讨论】:

      • 我不是在说维基百科的服务器,我说的是假设你有一个名为 www.foo.com 的站点,而你的 android 应用程序包是 com.example.foo,那么在您的网页中,您需要包含 href="android-app://com.example.foo/ 并在您的 android 清单中包含 http 和 https 架构。这将始终在您的应用中打开结果并显示应用图标铬也是如此。它有效而且很简单。我只是在上面解释了维基百科的工作原理。
      【解决方案4】:

      顺便说一下,这称为App Indexing,Google 有办法在 Android 中进行设置

      以下是如何为您的应用内容指定deep link

      1. 在您的 Android 清单文件中,为应该可以从 Google 搜索结果启动的活动添加一个或多个 &lt;intent-filter&gt; 元素。
      2. 添加一个 &lt;action&gt; 标记,指定 ACTION_VIEW 意图操作。
      3. 为活动接受的每个数据 URI 格式添加一个 &lt;data&gt; 标记。这是声明深层链接格式的主要机制。
      4. BROWSABLEDEFAULT 意图类别添加 &lt;category&gt;

        • BROWSABLE 是必需的,以便可以从 Web 浏览器执行该意图。没有它,点击浏览器中的链接将无法解析您的应用,只有当前的网络浏览器会响应该 URL。
        • 如果您的唯一兴趣是从 Google 搜索结果中提供指向您的应用的深层链接,则不需要 DEFAULT。但是,如果您希望 Android 应用程序在用户单击指向您网站的任何其他网页的链接时做出响应,则需要 DEFAULT 类别。区别在于,谷歌搜索结果中使用的意图包括您的应用程序的身份,因此意图明确指向您的应用程序作为接收者 - 指向您网站的其他链接不知道您的应用程序身份,因此 DEFAULT 类别声明您的应用可以接受隐式意图。

      示例

      <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" />
              <!-- Accepts URIs that begin with "http://example.com/gizmos” -->
              <data
                  android:scheme="http"
                  android:host="example.com"
                  android:pathPrefix="/gizmos" />
      
              <category android:name="android.intent.category.DEFAULT" />
      
              <category android:name="android.intent.category.BROWSABLE" />
          </intent-filter>
      </activity>
      

      在此示例中,您的应用会响应深层链接,例如...

      intent 过滤器的&lt;data&gt; 元素必须至少提供android:scheme 属性。然后您可以添加其他属性以进一步细化活动接受的URI 类型。

      更多信息可以找到here...

      【讨论】:

      • @animaonline 你怎么看这个?您无需访问 Wikipedia 的服务器!您所需要的只是您构建的应用程序。我所有的答案都是进入您的应用程序的代码,仅此而已。让我知道你的想法!
      【解决方案5】:

      Android 引入应用链接 api 将原生应用内容整合到 google 搜索结果中。文档说:

      Google's web crawling bot (Googlebot), which crawls and indexes web sites for the Google search engine, can also index content in your Android app. By opting in, you can allow Googlebot to crawl the content in the APK through the Google Play Store to index the app content. To indicate which app content you’d like Google to index, simply add link elements either to your existing Sitemap file or in the <head> element of each web page in your site, in the same way as you would for web pages.
      
      The deep links that you share with Google Search must take this URI format:
      
      android-app://<package_name>/<scheme>/<host_path>
      The components that make up the URI format are:
      
      package_name. Represents the package name for your APK as listed in the Google Play Developer Console.
      scheme. The URI scheme that matches your intent filter.
      host_path. Identifies the specific content within your application.
      The following sections describe how to add a deep link URI to your Sitemap or web pages.
      

      同样重要的是,如果用户在手机上没有该应用,但您仍希望内容在谷歌搜索结果中正确格式化,您需要使用元标记。文档 说:

      元标记是网站管理员提供搜索引擎的好方法 与他们的网站信息。元标记可用于提供 信息给各种客户,每个系统只处理 他们理解的元标记并忽略其余部分。元标签是 添加到 HTML 页面的部分,通常看起来像 这个:

      参考-https://support.google.com/webmasters/answer/79812?hl=en

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-24
        • 2023-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多