Added in API level 1

SearchRecentSuggestionsProvider


open class SearchRecentSuggestionsProvider : ContentProvider
kotlin.Any
   ↳ android.content.ContentProvider
   ↳ android.content.SearchRecentSuggestionsProvider

This superclass can be used to create a simple search suggestions provider for your application. It creates suggestions (as the user types) based on recent queries and/or recent views.

In order to use this class, you must do the following.

  • Implement and test query search, as described in android.app.SearchManager. (This provider will send any suggested queries via the standard ACTION_SEARCH Intent, which you'll already support once you have implemented and tested basic searchability.)
  • Create a Content Provider within your application by extending android.content.SearchRecentSuggestionsProvider. The class you create will be very simple - typically, it will have only a constructor. But the constructor has a very important responsibility: When it calls setupSuggestions(java.lang.String,int), it configures the provider to match the requirements of your searchable activity.
  • Create a manifest entry describing your provider. Typically this would be as simple as adding the following lines:
    <!-- Content provider for search suggestions -->
          <provider android:name="YourSuggestionProviderClass"
                    android:authorities="your.suggestion.authority" />
  • Please note that you do not instantiate this content provider directly from within your code. This is done automatically by the system Content Resolver, when the search dialog looks for suggestions.
  • In order for the Content Resolver to do this, you must update your searchable activity's XML configuration file with information about your content provider. The following additions are usually sufficient:
    android:searchSuggestAuthority="your.suggestion.authority"
          android:searchSuggestSelection=" ? "
  • In your searchable activities, capture any user-generated queries and record them for future searches by calling SearchRecentSuggestions.saveRecentQuery().

Summary

Constants
static Int

This mode bit configures the database to include a 2nd annotation line with each entry.

static Int

This mode bit configures the database to record recent queries.

Inherited constants
Public constructors

Public methods
open Int
delete(uri: Uri, selection: String?, selectionArgs: Array<String!>?)

This method is provided for use by the ContentResolver.

open String?
getType(uri: Uri)

This method is provided for use by the ContentResolver.

open Uri?
insert(uri: Uri, values: ContentValues?)

This method is provided for use by the ContentResolver.

open Boolean

This method is provided for use by the ContentResolver.

open Cursor?
query(uri: Uri, projection: Array<String!>?, selection: String?, selectionArgs: Array<String!>?, sortOrder: String?)

This method is provided for use by the ContentResolver.

open Int
update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<String!>?)

This method is provided for use by the ContentResolver.

Protected methods
open Unit
setupSuggestions(authority: String!, mode: Int)

In order to use this class, you must extend it, and call this setup function from your constructor.

Inherited functions

Constants

DATABASE_MODE_2LINES

Added in API level 1
static val DATABASE_MODE_2LINES: Int

This mode bit configures the database to include a 2nd annotation line with each entry. optional

Value: 2

DATABASE_MODE_QUERIES

Added in API level 1
static val DATABASE_MODE_QUERIES: Int

This mode bit configures the database to record recent queries. required

Value: 1

Public constructors

SearchRecentSuggestionsProvider

SearchRecentSuggestionsProvider()

Public methods

delete

Added in API level 1
open fun delete(
    uri: Uri,
    selection: String?,
    selectionArgs: Array<String!>?
): Int

This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.

Parameters
uri Uri: The full URI to query, including a row ID (if a specific record is requested). This value cannot be null.
selection String?: An optional restriction to apply to rows when deleting. This value may be null.
selectionArgs Array<String!>?: This value may be null.
Return
Int The number of rows affected.
Exceptions
android.database.SQLException

getType

Added in API level 1
open fun getType(uri: Uri): String?

This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.

Parameters
uri Uri: the URI to query. This value cannot be null.
Return
String? a MIME type string, or null if there is no type.

insert

Added in API level 1
open fun insert(
    uri: Uri,
    values: ContentValues?
): Uri?

This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.

Parameters
uri Uri: The content:// URI of the insertion request. This value cannot be null.
values ContentValues?: A set of column_name/value pairs to add to the database. This value may be null.
Return
Uri? The URI for the newly inserted item. This value may be null.

onCreate

Added in API level 1
open fun onCreate(): Boolean

This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.

Return
Boolean true if the provider was successfully loaded, false otherwise

query

Added in API level 1
open fun query(
    uri: Uri,
    projection: Array<String!>?,
    selection: String?,
    selectionArgs: Array<String!>?,
    sortOrder: String?
): Cursor?

This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.

Parameters
uri Uri: The URI to query. This will be the full URI sent by the client; if the client is requesting a specific record, the URI will end in a record number that the implementation should parse and add to a WHERE or HAVING clause, specifying that _id value. This value cannot be null.
projection Array<String!>?: The list of columns to put into the cursor. If null all columns are included.
selection String?: A selection criteria to apply when filtering rows. If null then all rows are included.
selectionArgs Array<String!>?: You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings. This value may be null.
sortOrder String?: How the rows in the cursor should be sorted. If null then the provider is free to define the sort order.
Return
Cursor? a Cursor or null.

update

Added in API level 1
open fun update(
    uri: Uri,
    values: ContentValues?,
    selection: String?,
    selectionArgs: Array<String!>?
): Int

This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.

Parameters
uri Uri: The URI to query. This can potentially have a record ID if this is an update request for a specific record. This value cannot be null.
values ContentValues?: A set of column_name/value pairs to update in the database. This value may be null.
selection String?: An optional filter to match rows to update. This value may be null.
selectionArgs Array<String!>?: This value may be null.
Return
Int the number of rows affected.

Protected methods

setupSuggestions

Added in API level 1
protected open fun setupSuggestions(
    authority: String!,
    mode: Int
): Unit

In order to use this class, you must extend it, and call this setup function from your constructor. In your application or activities, you must provide the same values when you create the android.provider.SearchRecentSuggestions helper.

Parameters
authority String!: This must match the authority that you've declared in your manifest.
mode Int: You can use mode flags here to determine certain functional aspects of your database. Note, this value should not change from run to run, because when it does change, your suggestions database may be wiped.