I have written a photo application that streams images from an external source to my app on a tablet (Samsung Galaxy TAB S). I have decided to use the external SD card in the tablet as storage, as the internal storage often runs out of space. Plus, I need to remove it to backup all the images.
Everything works fine for "reading" the JPGs, but when it comes to "writing" JPGs from the stream to the SD Card, permission is denied.
I have already set the WRITE_EXTERNAL_STORAGE
permission, but this does not work using the Android SDK 25.2.5, as Android changed the way the permissions work for external access.
fWriteStorage:=JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE);
PermissionsService.RequestPermissions([fReadStorage, fWriteStorage], DisplayRationale);
What I want to do is invoke the Android System Folder Chooser Dialog to allow access for the App to write to the SD card. As described here: SD Card on Android 5.0 and Later.
Does anyone know how I can invoke the permissions selector for the SD card in in Delphi 10.3 Rio? Similar to all apps including TotalCommander for Android, that need write access to an external SD card.
I have now tried again, using the following code and still no luck. I need to create new folders for image galleries, and the folder can not be created.
fWriteStorage := JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE);
if PermissionsService.IsPermissionGranted(fWriteStorage) then
begin
applog('IsPermissionGranted: TRUE');
if ForceDirectories(System.IOUtils.TPath.Combine(GLOBAL_SDCARD, 'FoxyTab/Storage')) then
AppLog('GLOBAL_SDCARD Created')
else
AppLog('Can not create SD CARD folder ' + System.IOUtils.TPath.Combine(GLOBAL_SDCARD, 'FoxyTab/Storage'));
PermissionsService.RequestPermissions([fWriteStorage],
procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>)
begin
if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then
begin
AppLog('Access Granted');
if ForceDirectories(System.IOUtils.TPath.Combine(GLOBAL_SDCARD, 'FoxyTab/Storage')) then
AppLog('GLOBAL_SDCARD Created')
else
AppLog('Can not create SD CARD folder ' + System.IOUtils.TPath.Combine(GLOBAL_SDCARD, 'FoxyTab/Storage'));
end
else
begin
AppLog('Access Denied');
end;
end);
I always get "Access Granted", but the folder can not be created.
The SD card is not internal to the tablet, but a "removable" microSD card because I need to remove it when the galleries are full to backup to another device (PC/MAC). The path to the card is /storage/2266-7298/. Different from what is returned using the standard directory.