2

I am trying to learn the content provider implementation and how it works. I tried the sample notepad application in Android SDK and everything is working fine. I am able to create new notes and save them and edit them.

I tried changing this content provider to custom implementation. This is working fine. But I dont understand the below implementations

1) why is the Notepad.java defined two times once within the folder "com.example.android.notepad" and then within "com.google.provider".

2) How is the intent type "content://com.vinod.provider.NotePad/notes" going to the list and "content://com.vinod.provider.NotePad/notes/2" going to the edit activity? how is this controlled?

3) in the manifest I see mime type like "vnd.android.cursor.dir/vnd.google.note". what does the vnd.android.cursor.dir and vnd.android.cursor.item stands for. And what is "vnd.google.note"

Can some one please explain me these questions. Thank you for your time and help.

Shoban
  • 22,920
  • 8
  • 63
  • 107
Vinod
  • 31,933
  • 35
  • 96
  • 119

2 Answers2

0

In new ADT 21.1 NotePad sample app: adt-bundle-windows-x86_64\sdk\samples\android-17_1\NotePad Looks like com.google.provider folder is not used any more, so there is only one Notepad.java file in "com.example.android.notepad" folder.

Wayne
  • 1
0

1) Two Files

They are two different classes -- com.example.android.notepad is a class that implements the application. com.google.provider.notepad is a class that implements the ContentProvider.

The application provides the user interface, the ContentProvider provides data storage.

Looking at This link to the Notepad ContentProvider example, its' naming is much clearer.


2) URI Matching

Referencing NotepadProvider.java:

  sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
  sUriMatcher.addURI(NotePad.AUTHORITY, "notes", NOTES);
  sUriMatcher.addURI(NotePad.AUTHORITY, "notes/#", NOTE_ID);

UriMatcher takes a list of patterns. NotePad.AUTHORITY is the base of the content URI.

"notes" is one pattern to match, and the enum NOTES is returned. "notes/#" is one pattern to match, and the enum NOTE_ID is returned.

switch (sUriMatcher.match(uri)) {
case NOTES:
   ...
   break;

case NOTES:
   ...
   break;

default:
   ...
   break;
}

Is the pattern for making a decision to run different code based on URI


3) MIME types

MIME types are optional. You probably don't need to do anything with them.

jcwenger
  • 11,383
  • 1
  • 53
  • 65