Added in API level 35

EnterpriseGlobalSearchSession


open class EnterpriseGlobalSearchSession
kotlin.Any
   ↳ android.app.appsearch.EnterpriseGlobalSearchSession

Provides a connection to the work profile's AppSearch databases that explicitly allow access from enterprise sessions. Databases may have additional required permissions and restricted fields when accessed through an enterprise session that they normally would not have.

EnterpriseGlobalSearchSession will only return results when created from the main user context and when there is an associated work profile. If the given context is either not the main user or does not have a work profile, queries will successfully complete with empty results, allowing clients to query the work profile without having to account for whether it exists or not.

Summary

Public methods
open Unit
getByDocumentId(packageName: String, databaseName: String, request: GetByDocumentIdRequest, executor: Executor, callback: BatchResultCallback<String!, GenericDocument!>)

Retrieves GenericDocument documents, belonging to the specified package name and database name and identified by the namespace and ids in the request, from the GlobalSearchSession database.

open Unit
getSchema(packageName: String, databaseName: String, executor: Executor, callback: Consumer<AppSearchResult<GetSchemaResponse!>!>)

Retrieves the collection of schemas most recently successfully provided to android.app.appsearch.AppSearchSession#setSchema for any types belonging to the requested package and database that the caller has been granted access to.

open SearchResults
search(queryExpression: String, searchSpec: SearchSpec)

Retrieves documents from all AppSearch databases that the querying application has access to.

Public methods

getByDocumentId

Added in API level 35
open fun getByDocumentId(
    packageName: String,
    databaseName: String,
    request: GetByDocumentIdRequest,
    executor: Executor,
    callback: BatchResultCallback<String!, GenericDocument!>
): Unit

Retrieves GenericDocument documents, belonging to the specified package name and database name and identified by the namespace and ids in the request, from the GlobalSearchSession database.

If the package or database doesn't exist or if the calling package doesn't have access, the gets will be handled as failures in an AppSearchBatchResult object in the callback.

Parameters
packageName String: the name of the package to get from This value cannot be null.
databaseName String: the name of the database to get from This value cannot be null.
request GetByDocumentIdRequest: a request containing a namespace and IDs to get documents for. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback BatchResultCallback<String!, GenericDocument!>: Callback to receive the pending result of performing this operation. The keys of the returned AppSearchBatchResult are the input IDs. The values are the returned GenericDocuments on success, or a failed AppSearchResult otherwise. IDs that are not found will return a failed AppSearchResult with a result code of AppSearchResult#RESULT_NOT_FOUND. If an unexpected internal error occurs in the AppSearch service, BatchResultCallback#onSystemError will be invoked with a Throwable. This value cannot be null.

getSchema

Added in API level 35
open fun getSchema(
    packageName: String,
    databaseName: String,
    executor: Executor,
    callback: Consumer<AppSearchResult<GetSchemaResponse!>!>
): Unit

Retrieves the collection of schemas most recently successfully provided to android.app.appsearch.AppSearchSession#setSchema for any types belonging to the requested package and database that the caller has been granted access to.

If the requested package/database combination does not exist or the caller has not been granted access to it, then an empty GetSchemaResponse will be returned.

Parameters
packageName String: the package that owns the requested AppSearchSchema instances. This value cannot be null.
databaseName String: the database that owns the requested AppSearchSchema instances. This value cannot be null.
executor Executor: Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback Consumer<AppSearchResult<GetSchemaResponse!>!>: The pending GetSchemaResponse containing the schemas that the caller has access to or an empty GetSchemaResponse if the request package and database does not exist, has not set a schema or contains no schemas that are accessible to the caller. This value cannot be null.
Added in API level 35
open fun search(
    queryExpression: String,
    searchSpec: SearchSpec
): SearchResults

Retrieves documents from all AppSearch databases that the querying application has access to.

Applications can be granted access to documents by specifying android.app.appsearch.SetSchemaRequest.Builder#setSchemaTypeVisibilityForPackage when building a schema.

Document access can also be granted to system UIs by specifying android.app.appsearch.SetSchemaRequest.Builder#setSchemaTypeDisplayedBySystem when building a schema.

See AppSearchSession#search for a detailed explanation on forming a query string.

This method is lightweight. The heavy work will be done in android.app.appsearch.SearchResults#getNextPage.

Parameters
queryExpression String: query string to search. This value cannot be null.
searchSpec SearchSpec: spec for setting document filters, adding projection, setting term match type, etc. This value cannot be null.
Return
SearchResults a SearchResults object for retrieved matched documents. This value cannot be null.