Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Q: SQLite database in scoped storage

In Android Q introduced new Scoped storage feature, which says:

apps that target Android 10 (API level 29) and higher are given scoped access into external storage, or scoped storage, by default. Such apps have access only to the app-specific directory on external storage, as well as specific types of media that the app has created.

I have my app that creates SQLite database on external storage, such that when app uninstalls database still alive and can be used later as recovery or be used outside of Android device (let's say in PC)

How should I achieve the same effect with Android Q? More precisely if database stored in external public directory - how can I read this database using standard SQLiteOpenHelper?

like image 618
Barmaley Avatar asked Jan 10 '20 13:01

Barmaley


1 Answers

You could try to use the solution from the docs:
https://developer.android.com/training/data-storage/compatibility

  • Target Android 9 (API level 28) or lower.
  • If you target Android 10 (API level 29) or higher, set the value of requestLegacyExternalStorage to true in your app's manifest file:
<manifest ... >
    <!-- This attribute is "false" by default on apps targeting Android 10 or higher. -->
    <application android:requestLegacyExternalStorage="true" ... >
    ...
    </application>
</manifest>
like image 197
Merov Avatar answered Oct 04 '22 02:10

Merov