Reputation: 21
I have been unsuccessfully trying to access database trough content provider for couple of days now.
I think that I don't understand the syntax of the Uri that is used to point to the database. Maybe I don't understand correctly the Android developer's documentation about the format of Uri.
I have a database which name is "testdatabase.db", table which name is "table1" and a class named DbProvider
that subclasses ContentProvider
. The database is created successfully and I can make queries to it using adb shell, but when I try to make queries from client, I got IllegalArgumentException Unknown uri: content://com.test.dbprovider/testdatabase.db
Could somebody please explain what is the correct format of Uri in my case? And what is the syntax of authority part of provider? Can an authority be named for example com.test.foo
and it should still work or should the last part after dot be a class name or something like that?
I have also made the necessary provider tags to AndroidManifest.xml
file.
Upvotes: 2
Views: 6020
Reputation: 3
The DB is referred to using the authority. so com.test.dbprovider.testdatabase
. do not put ".db"
also ensure your authority is exactly as specified as your package. so if you package is com.test.contentprovider
do not add "dbprovider" randomly.
ensure the authority is identical in the android manifest.
summary content://com.text.dbprovider.testdatabase/table1
Upvotes: 0
Reputation: 23977
You are getting the exception because your content provider doesn't know the uri you specified. Since you haven't shown your code I can't say what is exactly wrong. Check the instance of UriMatcher in your content provider (You are using UriMatcher, right? If not check the docs.)
I guess you little misunderstood the uri in content provider. Normally, you don't use or even expose the database name in the uri (although you can if you like to). The uri is supposed to be a path to records in your database. In your example you could use something like content://com.text.dbprovider/table1
. The authority should be fully-qualified class name of the content provider. More about content providers' uris here.
I suggest you check the NotePad content provider implementation in samples.
Upvotes: 3