0

I need to open a large SQLite Database on Android 11 (api level 30). The Documentation says that "MANAGE_EXTERNAL_STORAGE" is a Problem in the Future.

Therefore, I read the Docs at: https://developer.android.com/training/data-storage/shared/documents-files and used:

public void openDirectory(Uri uriToLoad) {
    // Choose a directory using the system's file picker.
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);

    startActivityForResult(intent, 42);
}

@Override
public void onActivityResult(int requestCode, int resultCode,
        Intent resultData) {
    if (requestCode == 42
            && resultCode == Activity.RESULT_OK) {
        // The result data contains a URI for the document or directory that
        // the user selected.
        Uri uri = null;
        if (resultData != null) {
            uri = resultData.getData();
            DocumentFile dfile = DocumentFile.fromTreeUri(this, uri);
            DocumentFile[] fileList = dfile.listFiles();
            
        }
    }
}

If I understand the Documentation right, File is deprecated or can not be used with Files on the SD Card and DocumentFile/URI is the new thing. But to open the Database I use:

SQLiteDatabase.openDatabase(
        pFile.getAbsolutePath(),
        null,
        SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY))

So my Problem is: How to open a large (10Gb or more) Database with an URI or a DocumentFile.

Ps.: The Database is a RasterLite File with map images

user2304379
  • 59
  • 1
  • 8
  • You cannot open a SQLite database using a `Uri`, as SQLite requires filesystem-level access. In many cases, you could copy the content to some file that you control, but that is impractical for a 10GB database. How is that database getting onto the device? You may need to arrange for it to be in some location for which you have direct filesystem access (e.g., `getExternalFilesDir()` on `Context`). – CommonsWare Nov 30 '21 at 12:24
  • I copied the file on the SD Card from a PC. /storage/emulated/0/myApp/db.mbtiles. – user2304379 Nov 30 '21 at 14:16
  • Then copy it to a location that your app can read directly, such as the directory returned by `getExternalFilesDir()` on `Context`. – CommonsWare Nov 30 '21 at 14:16
  • I need to update or change the DB regularly and in the end there can be multiple of these DBs. – user2304379 Dec 01 '21 at 07:24
  • That means that you *really* need to copy them to a location that your app can read directly, such as the directory returned by `getExternalFilesDir()` on `Context`. – CommonsWare Dec 01 '21 at 11:58

0 Answers0