android - Google App Indexing for Android 的 setId 和 getUrl 方法之间的区别?

标签 android android-app-indexing

我正在为我的 Android 新闻应用程序集成谷歌应用程序索引。我已经阅读了官方文档和代码实验室示例。他们使用以下代码为索引 api 创建一个对象。

Thing object = new Thing.Builder()
            .setName(mTitle)
            .setUrl(mUrl)
            .build();

在探索过程中,我了解到 Thing.Builder 还有三个 setter,即 setId()setType()设置说明(),

虽然 setDescription() 是不言自明的,但我无法理解 setId()setUrl() 方法之间的区别,

来自文档,

public Thing.Builder setId (String id)

Sets the optional web URL of the content.`

,

public Thing.Builder setUrl (Uri url)

Sets the URL of the content in the app.

但我无法弄清楚两者之间的区别。这两种方法似乎都在设置内容的 url。出于我的目的,每篇新闻文章都有一个唯一的 url。那么我应该将该 url 设置为哪种方法?

还有getType方法有什么用?是设置“http”还是“https”

public Thing.Builder setType (String type)

Sets the schema.org type of the content.

最佳答案

基于此文档:https://developers.google.com/android/reference/com/google/android/gms/appindexing/Thing.Builder.html#public-methods

id:内容的等效 web url。

类型:内容的 schema.org 类型。

Type 是操作类型:https://developers.google.com/android/reference/com/google/android/gms/appindexing/Action#nested-class-summary

url:内容的应用URI,不能为空。 URI 必须是 HTTP(S) URL,或使用 App Indexing 格式。无论哪种情况,调用此方法的应用都需要处理相应的传入 Intent 并将用户带到该内容。

干杯,

MB

关于android - Google App Indexing for Android 的 setId 和 getUrl 方法之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37326928/

相关文章:

android - 将应用发布到生产后将近一天

android - 使用Android,如何将控制权传递回主线程?

android - 构建分布式 Android 应用程序

android - 具有单一主要 Activity 的应用的应用索引

cordova - 添加深层链接到 cordova 应用程序

java - 带 ExpandableList 的 PullToRefresh 布局

android - 我在哪里可以找到我的 android 手机中的/data/data 文件夹?

android - 如何为 Android 实现 Google App 索引

android - 如何从谷歌搜索网站结果中推广/打开应用程序?

android - 如何在 android 中为 AppIndexing 添加键?使应用程序更易于访问