简体   繁体   中英

C++ Builder 11.1 Android can't write a file to the Shared Documents folder

I am having difficulty with C++ Builder 11.1 Android trying to write a file to the Shared Documents folder. It worked with C++ Builder 10.3.1 but it doesn't work in 11.1

I have the permissions set properly in the Project Options Dialog box: Dangerous - Read External Storage = true Dangerous - Write External Storage = true

In the OnFormCreate method, I put in the necessary run time permissions as follows:

String FPermREAD;
String FPermWRITE;
DynamicArray<String> permissions;

FPermREAD  = JStringToString(TJManifest_permission::JavaClass->READ_EXTERNAL_STORAGE);
FPermWRITE = JStringToString(TJManifest_permission::JavaClass->WRITE_EXTERNAL_STORAGE);

permissions.Length = 2;
permissions[0] = FPermREAD;
permissions[1] = FPermWRITE;

PermissionsService()->RequestPermissions(permissions, LocationPermissionRequestResult);

In the routine to write the file...

AnsiString SharedPath;
AnsiString FileName;
FILE *OutStream;

SharedPath = System::Ioutils::TPath::GetSharedDocumentsPath(); 
// SharedPath = "/storage/emulated/0/Documents"

FileName = SharedPath +"/"+MyFileName;
OutStream = fopen(FileName.c_str(),"wb");  // This fails in 11.1 but not in 10.3.1
if(OutStream) {
     // write the file here
     fclose(OutStream);
     }

My Android device is Android 10. Any ideas why this is happening and how to fix it?

将 requestLegacyExternalStorage="true" 添加到清单文件中的应用程序标记。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM