I have a local SQLite database , and copy this file from my application directory to the user document directory with these codes:
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, doDbCopy);
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.load(new URLRequest("Data/MWData.db"));
private function doDbCopy(e:Event):void {
dbFile = File.documentsDirectory.resolvePath('MasterWin//db' + "//" + 'MWData.db');
loader.removeEventListener(Event.COMPLETE, doDbCopy);
var fileStream:FileStream = new FileStream();
fileStream.open(dbFile, FileMode.WRITE);
fileStream.writeBytes(loader.data);
fileStream.close();
connection = new SQLConnection();
connection.addEventListener(SQLEvent.OPEN, connect)
connection.open(dbFile, SQLMode.UPDATE);
stat = new SQLStatement();
stat.sqlConnection = connection;
}
but on android 11(API level 30) as google said :
On Android 11 (API level 30) and higher, you cannot use the ACTION_OPEN_DOCUMENT_TREE intent action to request access to the following directories:
The root directory of the internal storage volume.
The root directory of each SD card volume that the device manufacturer considers to be reliable, regardless of whether the card is emulated or removable. A reliable volume is one that an app can successfully access most of the time.
The Download directory.
Furthermore, on Android 11 (API level 30) and higher, you cannot use the ACTION_OPEN_DOCUMENT_TREE intent action to request that the user select individual files from the following directories:
The Android/data/ directory and all subdirectories.
The Android/obb/ directory and all subdirectories.
so as google said on this page Grant access to a directory's contents do we need new permission for document directory? because when I want to copy the SQLite database on android 11 to document directory, it shows me
[Fault] exception, information=Error: Error #3001: File or directory access denied,
Is there any other solution so that the end-user does not get involved in these problems and has easy access to the database? for example I copy the database to applicationStorageDirectory but this solution did not work for me either because it showed me an error message:
[Fault] exception, information=SQLError: 'Error #3125: Unable to open the database file.', details:'Connection closed.', operation:'open', detailID:'1001'
FYI: I ask android.permission.WRITE_EXTERNAL_STORAGE from my users and they granted it