我正在为我的 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.
最佳答案
id:内容的等效 web url。
类型:内容的 schema.org 类型。
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/