FileDocCategorySizeDatePackage
LocalProvider.javaAPI DocAndroid 5.1 API5334Thu Mar 12 22:22:12 GMT 2015android.app.activity

LocalProvider

public class LocalProvider extends ContentProvider
Simple test provider that runs in the local process.

Fields Summary
private static final String
TAG
private android.database.sqlite.SQLiteOpenHelper
mOpenHelper
private static final int
DATA
private static final int
DATA_ID
private static final android.content.UriMatcher
sURLMatcher
Constructors Summary
public LocalProvider()

    
Methods Summary
public intdelete(android.net.Uri url, java.lang.String where, java.lang.String[] whereArgs)

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

        int match = sURLMatcher.match(url);
        switch (match) {
            case DATA:
                return "vnd.android.cursor.dir/vnd.google.unit_tests.local";
            case DATA_ID:
                return "vnd.android.cursor.item/vnd.google.unit_tests.local";
            default:
                throw new IllegalArgumentException("Unknown URL");
        }
    
public android.net.Uriinsert(android.net.Uri url, ContentValues initialValues)

        return null;
    
public booleanonCreate()

        mOpenHelper = new DatabaseHelper(getContext());
        return true;
    
public android.database.Cursorquery(android.net.Uri url, java.lang.String[] projectionIn, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String sort)

        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

        // Generate the body of the query
        int match = sURLMatcher.match(url);
        switch (match) {
            case DATA:
                qb.setTables("data");
                break;
            case DATA_ID:
                qb.setTables("data");
                qb.appendWhere("_id=");
                qb.appendWhere(url.getPathSegments().get(1));
                break;
            default:
                throw new IllegalArgumentException("Unknown URL " + url);
        }

        SQLiteDatabase db = mOpenHelper.getReadableDatabase();
        Cursor ret = qb.query(db, projectionIn, selection, selectionArgs,
                              null, null, sort);

        if (ret == null) {
            if (false) Log.d(TAG, "Alarms.query: failed");
        } else {
            ret.setNotificationUri(getContext().getContentResolver(), url);
        }

        return ret;
    
public intupdate(android.net.Uri url, ContentValues values, java.lang.String where, java.lang.String[] whereArgs)

        int count;
        long rowId = 0;
        int match = sURLMatcher.match(url);
        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        switch (match) {
            case DATA_ID: {
                String segment = url.getPathSegments().get(1);
                rowId = Long.parseLong(segment);
                count = db.update("data", values, "_id=" + rowId, null);
                break;
            }
            default: {
                throw new UnsupportedOperationException(
                        "Cannot update URL: " + url);
            }
        }
        if (false) Log.d(TAG, "*** notifyChange() rowId: " + rowId);
        getContext().getContentResolver().notifyChange(url, null);
        return count;