How to get the URI of my SQLite database in an Android app?

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

+8
android database uri
source share
3 answers

this pretty simple method call is as follows

mDataBase.query(TABLE_NAME, columns, null, null, null, null, null);

where, TABLE_NAME = your SQLite table name and the columns are a string array like

String columns[] = new String[] { "Column1" };

If you need all the columns, you can pass null for the second argument.

Correction: As mentioned by several others, there is no URI.

-one
source share

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

+4
source share

There is no Uri in the database (except for the file where it is located). Data managed through a content provider has one. If you want to use the content conversion tool to complete the request, you must first create a content provider.

If you do not want to do this, just use the SQLiteDatabase query function - it returns a cursor that you can pass to SimpleCursorAdapter.

+1
source share

Source: https://habr.com/ru/post/650304/


All Articles