Reputation: 2218
Content uri generally is in this format
content://provider/product/1
Can a contenturi be made to accept such uri
content://provider/product/p1
can id be string?
I am trying to use ContentUris.withAppendedId(contentUri,id)
. this id seems to be type long.
Upvotes: 3
Views: 914
Reputation: 426
The problem is most likely in the way you've defined your UriMatcher.
You are probably using a pattern matcher for that uri and table which ends with a "#", so it's looking for a number.
Just add another matcher pattern exactly like what you already have but change the "#" to a "*" so it will also match on a string.
Here's an example I used where my table had both and _id column and a device_id column. The device_id column had a NOT NULL and UNIQUE constraint and held UUIDs. Either of the the two columns could be used as row identifiers.
sUriMatcher.addURI(AUTHORITY, DevicesTable.TABLE_NAME + "/#", DEVICE); sUriMatcher.addURI(AUTHORITY, DevicesTable.TABLE_NAME + "/*", DEVICE);
With this in place you can call either Uri.withAppendedPath(uri, _id); or URi.withAppendedPath(uri, uuid); and the matcher would find the right table.
Just be sure to adjust your ContentProvider to query the right fields for either case.
Upvotes: 1