如何将我的应用程序内容及其说明和预览添加到Google搜索结果中?

11

我发现了这篇文章:一种在应用中搜索内容的新方法,我对这个机会非常兴奋。我想要展示我的应用程序内容在谷歌搜索结果中,就像这样:

Google In Apps Search

但是这篇文章没有提供如何在应用中实现这些功能的任何信息。

我在我的应用程序中使用App Indexing API,如下面所述的文章:

这是我的代码:

...
  private GoogleApiClient mClient;

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ac_main);
    mClient = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
  }

  public Action getAction() {
    Thing object = new Thing.Builder()
        .setName("Test Content")
        .setDescription("Test Description")
        .setUrl(Uri.parse("myapp://com.example/"))
        .build();

    return new Action.Builder(Action.TYPE_VIEW).setObject(object)
        .setActionStatus(Action.STATUS_TYPE_COMPLETED)
        .build();
  }

  @Override
  public void onStart() {
    super.onStart();
    mClient.connect();
    AppIndex.AppIndexApi.start(mClient, getAction());
  }

  @Override
  public void onStop() {
    AppIndex.AppIndexApi.end(mClient, getAction());
    mClient.disconnect();
    super.onStop();
  }
...

以下是结果:

Search result

谷歌显示了我的应用程序的 测试内容 但没有描述和预览图像。 是否有任何方法可以在谷歌搜索结果中添加描述和预览图像? (就像Youtube或Twitter一样)

1个回答

2

试试这个

     Thing object = new Thing.Builder()
    .setName("Test Content")
    .setDescription("Test Description")
    .setUrl(Uri.parse("myapp://com.example/"))
  //.put("image","YourImageUrlHere")
  //I took one android logo url
    .put("image","http://www.logospike.com/wp-content/uploads/2015/10/Android_Logo_04.png")
    .build();

这段文字的意思是:
“该图像可以是一个ImageObject对象或者一个图像URL。
你正在使用Action.VIEW_TYPE。”

https://developers.google.com/android/reference/com/google/android/gms/appindexing/Action#TYPE_VIEW

根据文档, public static final String TYPE_VIEW
消费静态视觉内容的行为。 常量值:"https://schema.org/ViewAction"
请参阅https://schema.org/ViewAction,您可以在“来自Thing的属性”下找到“image”对象。
希望能帮到您。

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