Activity.onProvideAssistContent() example

梦想与她 提交于 2019-12-11 04:55:28

问题


Could anybody give mi an example of using Activity.onProvideAssistContent(), new in Android 6.0?


回答1:


For example for Music file you will use MusicRecording type from Schema.org in such way:

@Override 
    public void onProvideAssistContent(AssistContent assistContent) {
      super.onProvideAssistContent(assistContent);

  String structuredJson = new JSONObject()
       .put("@type", "MusicRecording")
       .put("@id", "https://example.com/music/recording")
       .put("name", "Album Title")
       .toString();

  assistContent.setStructuredData(structuredJson);
}

Full lists of JSON parameters you can find here Schema.org. And to play with JSON without need to compile app - JSON-LD site.




回答2:


Adding to Tajchert's answer, it's part of the Assist API. I just saw the new documentation for this new feature in Android Marshmallow. It's here: http://developer.android.com/training/articles/assistant.html

With a long press on the home button or saying the keyphrase the assistant shows a window with contextually relevant actions for the current activity. These potential actions might include deep links to other apps on the device.

This link provides an example of using Activity.onProvideAssistContent(): http://developer.android.com/training/articles/assistant.html#source_app



来源:https://stackoverflow.com/questions/32078146/activity-onprovideassistcontent-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!