> Optimizing Content for the Assistant
Android 6.0 Marshmallow introduces a new way for users to engage with apps through the assistant.
Users summon the assistant with a long-press on the Home button or by saying the keyphrase
.
》Your app can implement onProvideAssistContent(android.app.assist.AssistContent)
to improve assistant user experience by providing references to content related to the current activity.
@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); }If neither
onProvideAssistData(android.os.Bundle)
nor
onProvideAssistContent(android.app.assist.AssistContent)
callbacks are implemented, the system will still proceed and pass the information collected automatically to the assistant unless the current window is flagged as
secure
. As shown in Figure 3, the system uses the default implementations of
onProvideStructure(android.view.ViewStructure)
and
onProvideVirtualStructure(android.view.ViewStructure)
to collect text and view hierarchy information.
If neither onProvideAssistData(android.os.Bundle)
noronProvideAssistContent(android.app.assist.AssistContent)
callbacks are implemented, the system will still proceed and pass the information collected automatically to the assistant unless the current window is flagged as secure. As shown in Figure 3, the system uses the default implementations ofonProvideStructure(android.view.ViewStructure)
andonProvideVirtualStructure(android.view.ViewStructure)
to collect text and view hierarchy information.
If your app uses system alert
windows, it must promptly remove them as leaving them on the screen will degrade user experience and annoy the users.
If neither onProvideAssistData(android.os.Bundle)
noronProvideAssistContent(android.app.assist.AssistContent)
callbacks are implemented, the system will still proceed and pass the information collected automatically to the assistant unless the current window is flagged as secure. As shown in Figure 3, the system uses the default implementations ofonProvideStructure(android.view.ViewStructure)
andonProvideVirtualStructure(android.view.ViewStructure)
to collect text and view hierarchy information.
The assistant app must provide an implementation ofVoiceInteractionSessionService
and VoiceInteractionSession
as shown in this example and it requires the BIND_VOICE_INTERACTION
permission.
> Handling App Links
Android 6.0 (API level 23) and higher allow an app to designate itself as the default handler of a given type of link. If the user doesn't want the app to be the default handler, they can override this behavior fromSettings.
If neither onProvideAssistData(android.os.Bundle)
noronProvideAssistContent(android.app.assist.AssistContent)
callbacks are implemented, the system will still proceed and pass the information collected automatically to the assistant unless the current window is flagged as secure. As shown in Figure 3, the system uses the default implementations ofonProvideStructure(android.view.ViewStructure)
andonProvideVirtualStructure(android.view.ViewStructure)
to collect text and view hierarchy information.
The general steps for creating verified app links are as follows:
- In your app manifest, create intent filters for your website URIs.
- Configure your app to request verification of app links.
- Publish a Digital Asset Links JSON file on your websites to provide verification.
》 When a clicked link or programmatic request invokes a web URI intent, the Android system uses the following criteria, in descending order, to determine how to handle the request:
- The user has set app link associations: If the user has designated an app to handle app links, the system passes the web URI request to that app. A user can set this association in one of two ways: clicking Alwayswhen selecting an app from an app-selection dialog; or, opening Settings > Apps > (gear icon) > App links, selecting an app to use, and setting the app's App links property to the Open in this app option.
- The user has set no association, and there is one supporting app: If the user has not set a preference that matches the web URI request, and there is only one app declaring support for the intent’s URI pattern, the system automatically passes the request to that app.
- The user has set no association, and there are multiple supporting apps: If there are multiple apps declaring support for the web URI pattern, the system displays an app-selection dialog, prompting the user to select the most appropriate app.
<activity ...> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="http" /> <data android:scheme="https" /> <data android:host="www.android.com" /> </intent-filter> </activity>
<application> <activity android:name=”MainActivity”> <intent-filter android:autoVerify="true"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="http" android:host="www.domain1.com" /> <data android:scheme="https" android:host="www.domain1.com" /> </intent-filter> </activity> <activity android:name=”SecondActivity”> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="https" android:host="www.domain2.com" /> </intent-filter> </activity> </application
Important: The system verifies the JSON file via the encrypted HTTPS protocol. Make sure that your hosted file is accessible over an HTTPS connection, regardless of whether your app's intent filter includes https
.
》Note: Multiple apps associated with a domain may be signed with the same or different certificates.
[{ "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "example.com.puppies.app", "sha256_cert_fingerprints": ["14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"] } }, { "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "example.com.monkeys.app", "sha256_cert_fingerprints": ["14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"] } }]》 This listing indicates which apps are associated with which domains for that user:
Package
- Identifies an app by its package name, as declared in its manifest.Domains
- Shows the full list of hosts whose web links this app handles, using blank spaces as delimiters.Status
- Shows the current link-handling setting for this app. An app that has passed verification, and whose manifest containsandroid:autoVerify="true"
, shows a status ofalways
. The hexadecimal number after this status is related to the Android system's record of the user’s app linkage preferences. This value does not indicate whether verification succeeded.
Note: If a user changes the app link settings for an app before verification is complete, you may see a false positive for a successful verification, even though verification has failed. This verification failure, however, does not matter if the user explicitly enabled the app to open supported links without asking. This is because user preferences take precedence over programmatic verification (or lack of it). As a result, the link goes directly to your app, without showing a dialog, just as if verification had succeeded.
onProvideAssistData(android.os.Bundle)
nor
onProvideAssistContent(android.app.assist.AssistContent)
callbacks are implemented, the system will still proceed and pass the information collected automatically to the assistant unless the current window is flagged as
secure
. As shown in Figure 3, the system uses the default implementations of
onProvideStructure(android.view.ViewStructure)
and
onProvideVirtualStructure(android.view.ViewStructure)
to collect text and view hierarchy information.