Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the URI of my SQLite database in my Android app?

I have an Android app with a database called "myTestDB" with a table called "list_items". I want to use the Cursor getContentResolver().query() method to get a cursor to add to a SimpleCursorAdapter. The first argument of the query() method is a URI and I'm not sure what the URI should look like.

like image 461
alexD Avatar asked Dec 20 '10 07:12

alexD


2 Answers

You do not use getContentResolver() to access a SQLite database directly. You use getContentResolver() when working with content providers. You call query() on a SQLiteDatabase object to get a Cursor for use with SimpleCursorAdapter.

like image 198
CommonsWare Avatar answered Sep 27 '22 19:09

CommonsWare


A database doesn't have a Uri (other than the file where it's located). Data managed through a content provider has one. If you want to use the content resolver to perform a query, you need to write a content provider first.

If you don't want to do that, simply use SQLiteDatabase's query function - it returns a Cursor that you can pass to the SimpleCursorAdapter.

like image 24
EboMike Avatar answered Sep 27 '22 18:09

EboMike