FileDocCategorySizeDatePackage
SearchIndexablesProvider.javaAPI DocAndroid 5.1 API7133Thu Mar 12 22:22:10 GMT 2015android.provider

SearchIndexablesProvider

public abstract class SearchIndexablesProvider extends android.content.ContentProvider
Base class for a search indexable provider. Such provider offers data to be indexed either as a reference to an XML file (like a {@link android.preference.PreferenceScreen}) or either as some raw data.
see
SearchIndexableResource
see
SearchIndexableData
see
SearchIndexablesContract To create a search indexables provider, extend this class, then implement the abstract methods, and add it to your manifest like this:
<manifest>
...
<application>
...
<provider
android:name="com.example.MyIndexablesProvider"
android:authorities="com.example.myindexablesprovider"
android:exported="true"
android:grantUriPermissions="true"
android:permission="android.permission.READ_SEARCH_INDEXABLES"
<intent-filter>
<action android:name="android.content.action.SEARCH_INDEXABLES_PROVIDER" />
</intent-filter>
</provider>
...
</application>
</manifest>

When defining your provider, you must protect it with {@link android.Manifest.permission#READ_SEARCH_INDEXABLES}, which is a permission only the system can obtain.

hide

Fields Summary
private static final String
TAG
private String
mAuthority
private android.content.UriMatcher
mMatcher
private static final int
MATCH_RES_CODE
private static final int
MATCH_RAW_CODE
private static final int
MATCH_NON_INDEXABLE_KEYS_CODE
Constructors Summary
Methods Summary
public voidattachInfo(android.content.Context context, android.content.pm.ProviderInfo info)
Implementation is provided by the parent class.


                
    
          
        mAuthority = info.authority;

        mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        mMatcher.addURI(mAuthority, SearchIndexablesContract.INDEXABLES_XML_RES_PATH,
                MATCH_RES_CODE);
        mMatcher.addURI(mAuthority, SearchIndexablesContract.INDEXABLES_RAW_PATH,
                MATCH_RAW_CODE);
        mMatcher.addURI(mAuthority, SearchIndexablesContract.NON_INDEXABLES_KEYS_PATH,
                MATCH_NON_INDEXABLE_KEYS_CODE);

        // Sanity check our setup
        if (!info.exported) {
            throw new SecurityException("Provider must be exported");
        }
        if (!info.grantUriPermissions) {
            throw new SecurityException("Provider must grantUriPermissions");
        }
        if (!android.Manifest.permission.READ_SEARCH_INDEXABLES.equals(info.readPermission)) {
            throw new SecurityException("Provider must be protected by READ_SEARCH_INDEXABLES");
        }

        super.attachInfo(context, info);
    
public final intdelete(android.net.Uri uri, java.lang.String selection, java.lang.String[] selectionArgs)
Implementation is provided by the parent class. Throws by default, and cannot be overriden.

        throw new UnsupportedOperationException("Delete not supported");
    
public java.lang.StringgetType(android.net.Uri uri)

        switch (mMatcher.match(uri)) {
            case MATCH_RES_CODE:
                return SearchIndexablesContract.XmlResource.MIME_TYPE;
            case MATCH_RAW_CODE:
                return SearchIndexablesContract.RawData.MIME_TYPE;
            case MATCH_NON_INDEXABLE_KEYS_CODE:
                return SearchIndexablesContract.NonIndexableKey.MIME_TYPE;
            default:
                throw new IllegalArgumentException("Unknown URI " + uri);
        }
    
public final android.net.Uriinsert(android.net.Uri uri, android.content.ContentValues values)
Implementation is provided by the parent class. Throws by default, and cannot be overriden.

        throw new UnsupportedOperationException("Insert not supported");
    
public android.database.Cursorquery(android.net.Uri uri, java.lang.String[] projection, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String sortOrder)

        switch (mMatcher.match(uri)) {
            case MATCH_RES_CODE:
                return queryXmlResources(null);
            case MATCH_RAW_CODE:
                return queryRawData(null);
            case MATCH_NON_INDEXABLE_KEYS_CODE:
                return queryNonIndexableKeys(null);
            default:
                throw new UnsupportedOperationException("Unknown Uri " + uri);
        }
    
public abstract android.database.CursorqueryNonIndexableKeys(java.lang.String[] projection)
Returns all {@link android.provider.SearchIndexablesContract.NonIndexableKey}. Those are the non indexable data keys.

param
projection list of {@link android.provider.SearchIndexablesContract.NonIndexableKey} columns to put into the cursor. If {@code null} all supported columns should be included.

public abstract android.database.CursorqueryRawData(java.lang.String[] projection)
Returns all {@link android.provider.SearchIndexablesContract.RawData}. Those are the raw indexable data.

param
projection list of {@link android.provider.SearchIndexablesContract.RawData} columns to put into the cursor. If {@code null} all supported columns should be included.

public abstract android.database.CursorqueryXmlResources(java.lang.String[] projection)
Returns all {@link android.provider.SearchIndexablesContract.XmlResource}. Those are Xml resource IDs to some {@link android.preference.PreferenceScreen}.

param
projection list of {@link android.provider.SearchIndexablesContract.XmlResource} columns to put into the cursor. If {@code null} all supported columns should be included.

public final intupdate(android.net.Uri uri, android.content.ContentValues values, java.lang.String selection, java.lang.String[] selectionArgs)
Implementation is provided by the parent class. Throws by default, and cannot be overriden.

        throw new UnsupportedOperationException("Update not supported");