2 years ago

#17623

test-img

prabhakaran

Create a database file in external storage in android 11 using room database

I have worked in android app, which is store the data in local database whenever internet is not available, The local database is placed in external storage inside the folder of the mobile phone, But now in android 11 they asked to use scoped storage.

Method1: I used the scoped storage and upload the apk in playstore but they rejected the app. Because of full access.

Method2: Create the app folder in public directory such as document or download. We can achieve to create and upload in playstore successfully. But Sometimes user uninstall the previous app and update the new version of the app. In that time new version of the app cannot access the local db..

I'm using room database and I create an object like this

public static final String A11_DB_PATH = 
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/appName/database/";

INSTANCE = Room.databaseBuilder(application, AppDatabase.class, A11_DB_PATH + DB_NAME)
           .allowMainThreadQueries()
           .openHelperFactory(factory)
           .fallbackToDestructiveMigration()
           .build();

android

android-room

android-external-storage

android-11

scoped-storage

0 Answers

Your Answer

Accepted video resources