@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@ExperimentalAppSearchApi
class ShortcutAdapter


Util methods for Document <-> shortcut conversion.

Summary

Constants

const String!
DEFAULT_NAMESPACE = "__shortcut_adapter_ns__"

Represents the default namespace which should be used as the androidx.appsearch.annotation.Document.Namespace for documents that are meant to be donated as a shortcut through androidx.core.content.pm.ShortcutManagerCompat.

Public functions

java-static ShortcutInfoCompat.Builder

Converts given document to a ShortcutInfoCompat.Builder, which can be used to construct a shortcut for donation through androidx.core.content.pm.ShortcutManagerCompat.

java-static Uri
getDocumentUri(document: Any)

Returns an uri that uniquely identifies the given document object.

java-static Uri

Returns an uri that identifies to the document associated with given document id.

Constants

DEFAULT_NAMESPACE

Added in 1.1.0-alpha07
const val DEFAULT_NAMESPACE = "__shortcut_adapter_ns__": String!

Represents the default namespace which should be used as the androidx.appsearch.annotation.Document.Namespace for documents that are meant to be donated as a shortcut through androidx.core.content.pm.ShortcutManagerCompat.

Public functions

createShortcutBuilderFromDocument

Added in 1.1.0-alpha07
java-static fun createShortcutBuilderFromDocument(context: Context, document: Any): ShortcutInfoCompat.Builder

Converts given document to a ShortcutInfoCompat.Builder, which can be used to construct a shortcut for donation through androidx.core.content.pm.ShortcutManagerCompat. Applicable data in the given document will be used to populate corresponding fields in ShortcutInfoCompat.Builder.

Note: Namespace of the given document is required to be set to DEFAULT_NAMESPACE if it will be used to create a shortcut; Otherwise an exception would be thrown.

See androidx.appsearch.annotation.Document.Namespace

Note: The ShortcutID in ShortcutInfoCompat.Builder will be set to match the id of given document. So an unique id across all documents should be chosen if the document is to be used to create a shortcut.

see getId

see androidx.appsearch.annotation.Document.Id

ShortcutInfoCompat.Builder created this way by default will be set to hidden from launcher. If remain hidden, they will not appear in launcher's surfaces (e.g. long press menu) nor do they count toward the quota defined in getMaxShortcutCountPerActivity

See setExcludedFromSurfaces.

Given document object will be stored in the form of Bundle in ShortcutInfoCompat.

The document that was stored in ShortcutInfoCompat is discarded when the shortcut is converted into android.content.pm.ShortcutInfo, meaning that the document will not be persisted in the shortcut object itself once the shortcut is published. i.e. Any shortcut returned from queries toward androidx.core.content.pm.ShortcutManagerCompat would not carry any document at all.

Parameters
document: Any

a document object annotated with androidx.appsearch.annotation.Document that carries structured data in a pre-defined format.

Returns
ShortcutInfoCompat.Builder

a ShortcutInfoCompat.Builder which can be used to construct a shortcut for donation through androidx.core.content.pm.ShortcutManagerCompat.

Throws
java.lang.IllegalArgumentException

An exception would be thrown if the namespace in the given document object does not match DEFAULT_NAMESPACE.

androidx.appsearch.exceptions.AppSearchException

An exception would be thrown if the given document object is not annotated with androidx.appsearch.annotation.Document or encountered an unexpected error during the conversion to GenericDocument.

getDocumentUri

Added in 1.1.0-alpha07
java-static fun getDocumentUri(document: Any): Uri

Returns an uri that uniquely identifies the given document object.

Parameters
document: Any

a document object annotated with androidx.appsearch.annotation.Document that carries structured data in a pre-defined format.

Throws
androidx.appsearch.exceptions.AppSearchException

if the given document object is not annotated with androidx.appsearch.annotation.Document or encountered an unexpected error during the conversion to GenericDocument.

getDocumentUri

Added in 1.1.0-alpha07
java-static fun getDocumentUri(id: String): Uri

Returns an uri that identifies to the document associated with given document id.

Parameters
id: String

id of the document.