Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The method for loading a database from a path file in API 28 (Android 9) is:

  1. First, make sure your app has the necessary permissions to access the file system by requesting the READEXTERNALSTORAGE permission in your app's manifest file.

  2. Use the SQLiteDatabase class to create a new database object and specify the path of the file you want to load:

SQLiteDatabase database = SQLiteDatabase.openDatabase("/path/to/your/file.db", null, SQLiteDatabase.OPEN_READONLY);
  1. You can then use the database object to perform any necessary operations on the database, such as querying data. If you are only reading data and don't need to modify it, you can pass in the SQLiteDatabase.OPEN_READONLY flag to the openDatabase method, as shown in the example above.

  2. When you are finished using the database, make sure to close it by calling the close method on the SQLiteDatabase object:

database.close();

Note: If you are using an external storage device, such as an SD card, you may need to handle additional permissions and device-specific issues.