Hi Elk,

Thanks again for your time and specifying your points. Finally I found
out the problem why the code wasn't working after lot of debugging.
Turned out that the table name and the Uri given was wrong. A stupid
typo was the issue.

Also, sorry I can't post the original code as I am under legal
restriction for not publishing my customer's code. Hence, I had to
improvise and write the whole thing.

@Brion,
Sorry for hacking the message. I didn't know this and in future I will
make sure not to hack existing message and will open new one.

Thanks everyone for helping. Finally I am able to make
something...working !!!

~Arpit.

On Sep 9, 11:29 pm, "A. Elk" <[email protected]> wrote:
> As far as I can tell from what you've posted, you're declaring
> CONTENT_URI as a String or some sort of string-related immutable
> class. If you look at the NotePad example, CONTENT_URI is of type Uri,
> and it's constructed using Uri.parse.
>
> You may be doing this, but what you've posted doesn't indicate it.
> Always be sure to post the exact code you're using.
>
> My first suggestion is to double-check that you have constructed the
> content URI correctly in the code, using Uri.parse.
>
> Next, do some debugging. I assume that what you *think* you're passing
> to your content provider is not what is actually getting to it. I also
> assume that you're already doing some debugging, since you know that
> uri.Match is returning -1.
>
> On Sep 8, 10:21 pm,Arpit<[email protected]> wrote:
>
>
>
> > Somehow myUriMatcheris not working properly and because of that I am
> > not able to do the CRUD operations on my tables.
>
> > I have the following structure of packages and classes:
>
> > com.arpit.provider : This has a class MyContentProvider which extends
> > ContentProvider class
> > com.arpit.tables :
> >         DatabaseHelper extends SQLiteOpenHelper
> >         KeyTable implements BaseColumns
> >         ParticipantTable implements BaseColumns
>
> > Now in MyContentProvider, I have done the following:
>
> > ...
> > public static final String AUTHORITY =
> > "com.arpit.provider.MyContentProvider";
> > ...
> > static{
> >        UriMatcheruriM = newUriMatcher(UriMatcher.NO_MATCH);
> >         uriM.addUri(AUTHORITY, "key", 0);
> >         uriM.addUri(AUTHORITY, "participant", 1);}
>
> > ...
> > public Cursor query(Uri uri, String[] projection, String selection,
> >                         String[] selectionArgs, String sortOrder) {
> >                 SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
> >                 switch(uriM.match(uri)){
> >                         case 0:
> >                                 qb.setTables("key");
> >                                 break;
> >                         case 1:
> >                                 qb.setTables("participant");
> >                                 break;
> >                 }
> > ....}
>
> > ...
>
> > In my KeyTable class, CONTENT_URI = "content://" +
> > MyContentProvider.AUTHORITY + "/key";
> > In my ParticipantTable class CONTENT_URI = "content://" +
> > MyContentProvider.AUTHORITY + "/participant";
>
> > In my AndroidManifest.xml file I have registered the provider as:
>
> > <provider android:name="com.arpit.providers.MyContentProvider"
> >         android:authorities="com.arpit.providers.MyContentProvider"></
> > provider>
>
> > Now I make the query call with the following statement in my
> > HomeActivity:
>
> > Cursor cursor = getContentResolver().query(KeyTable.CONTENT_URI, new
> > String[] { KeyTable.col1 }, "_id='1'", null,  null);
>
> > My problem is when the Query Method is called and the Switch block is
> > executed the uriM.match returns always -1 (irrespective of whether it
> > is KeyTable.CONTENT_URI or ParticipantTable.CONTENT_URI).
>
> > Could you let me know what wrong am I doing because of which it is not
> > working.
>
> > From the note pad example I see during debug the only difference is
> > they call managedQuery instead of getContentReslover().query(...). I
> > tried firing managedQuery(...) in my HomeActivity class, but that also
> > result in uriM.match(uri) to return -1.
>
> > It will be great if you could help me out.
>
> > Thanks & Regards,
> >Arpit
>
> > On Aug 25, 10:20 pm, "A. Elk" <[email protected]> wrote:
>
> > > The Note Pad example is pretty good for URI content matching.
>
> > > Basically, you define one or more URIs for a ContentProvider. Don't
> > > think of them as "URLs", just think of them as strings with a
> > > particular format. Using web domains in them is a easy, nearly
> > > foolproof way to ensure that each URI is unique. For example, I can
> > > safely use the content URI 
> > > content://database.lancaster.dambusters.gmail.com
> > > because that's my unique GMail address.
>
> > > Patterns come in when you want a ContentProvider to return different
> > > things depending on the exact URI. In the Note Pad sample (*not* the
> > > tutorial), there are 3 patterns corresponding to 3 "forms" of data: a
> > > list of notes, a single note, or a set of notes compatible with the
> > > LiveFolder widget. The "list of notes" form is set up in the code and
> > > the manifest so that it returns a set of records. The single note
> > > returns exactly one note, and I forget offhand what LiveFolders does.
> > > Let's look at the first two.
>
> > > For set of notes, you just specify a "base" URI. The Provider returns
> > > all the notes in the database that match your criteria.
>
> > > For a single note, you specify a pattern that is the "single note"
> > > base URI with a note ID number appended to it. The ID number is the
> > > value of the "_ID" column for the record you want. The Provider
> > > returns that particular note. As written, the Provider can also filter
> > > the note by selection criteria.
>
> > > If you look in the code for the Provider, you'll see that it defines 
> > > aUriMatcher. You useUriMatcher.addUri() to match an "authority" (a
> > > base URI without a specific pattern) and a pattern to a value. When a
> > > URI comes in to the query() method, you useUriMatcher.match to match
> > > the incoming URI to a pattern. The method returns the value that you
> > > associated with the pattern in addUri(). TheUriMatcheris defined in
> > > a static block at the end of the code.
>
> > > As a note, you can use "?" in a pattern as a wildcard to match any
> > > string, and "#" to match any number. The "#" is used to match a single
> > > note in Note Pad.
>
> > > The Note Pad code is hard to understand because it's designed to
> > > accept alternate actions. This allows other apps to access the
> > > ContentProvider by specifying the proper authority and MimeType. You
> > > can ignore this, basically. The mime type tells the calling app what
> > > it's gonna get back from the Provider. If the type is
> > > vnd.android.cursor.dir, then the calling app knows it may get back
> > > more than one row, whereas if it gets back cursor.item, it gets back
> > > only one item. Incoming Intents have to specify a mimeType so that
> > > they exactly match Note Pad's intent filters. For example, an app that
> > > sends an Intent with action.GET_CONTENT but mime type
> > > vnd.android.cursor.dir won't match any of Note Pad's intent filters.
>
> > > The elkmeister.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to