Listing 918 srccomcookbookdatastorageDiary ContentProviderjava

package com.cookbook.datastorage;

import android.content.ContentProvider; import android.content.ContentValues;

import android.content.UriMatcher; import android.database.Cursor;

import android.database.sqlite.SQLiteQueryBuilder; import android.net.Uri;

import com.cookbook.data.Constants; import com.cookbook.data.MyDB;

public class DiaryContentProvider extends ContentProvider { private MyDB dba;

private static final UriMatcher sUriMatcher; //the code returned for URI match to components private static final int DIARIES=1;

public static final String AUTHORITY = "com.cookbook.datastorage"; static {

sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); sUriMatcher.addURI(AUTHORITY, Constants.TABLE_NAME, DIARIES);

^Override public int delete(Uri uri, String selection, String[] selectionArgs) { return 0;

public String getType(Uri uri) {return null;}

public Uri insert(Uri uri, ContentValues values) {return null;} public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {return 0;}

^Override public boolean onCreate() {

dba = new MyDB(this.getContext());

return false;

^Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Cursor c=null;

switch (sUriMatcher.match(uri)) { case DIARIES:

c = dba.getdiaries(); break; default:

throw new IllegalArgumentException(

c.setNotificationUri(getContext().getContentResolver(), uri); return c;

The provider needs to be specified in the AndroidManifest XML file to be accessible, as shown in Listing 9.19.

Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook


Post a comment