简体   繁体   English

C++ Builder 11.1 Android 无法将文件写入共享文档文件夹

[英]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.我在使用 C++ Builder 11.1 Android 尝试将文件写入共享文档文件夹时遇到困难。 It worked with C++ Builder 10.3.1 but it doesn't work in 11.1它适用于 C++ Builder 10.3.1,但不适用于 11.1

I have the permissions set properly in the Project Options Dialog box: Dangerous - Read External Storage = true Dangerous - Write External Storage = true我在项目选项对话框中正确设置了权限:危险 - 读取外部存储 = true 危险 - 写入外部存储 = true

In the OnFormCreate method, I put in the necessary run time permissions as follows:在 OnFormCreate 方法中,我输入了必要的运行时权限,如下所示:

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?我的 Android 设备是 Android 10。任何想法为什么会发生这种情况以及如何解决它?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将文本文件写入 Android 中的文档文件夹 - Can't write text files to documents folder in Android Android JCIFS将文件写入共享的网络文件夹(无法连接到服务器) - Android JCIFS write file to shared network folder (Can't connect to server) 我可以从txt文件内部存储空间(“文档”文件夹中读取和写入),但是无法浏览到该位置,因为它不存在 - I can read and write from a txt file internal storage (documents folder) but cannot browse to that location because it doesn't exist 我无法从 android 的下载文件夹中获取文档 - I can't fetch documents from the downloads folder in android 无法在Android中写入文件 - Can't write to file in Android 使用 Cordova android 应用程序,我如何访问(读/写)Win10 设备共享文件夹中的 SQLite 文件? - With Cordova android app, how I can access (read/write) SQLite file at shared folder in Win10 device? 无法删除C ++中的空文件夹 - Can't remove an empty folder in C++ 无法在c ++中加载和解析android上的xml文件 - Can't load and parse xml file on android in c++ Android写入文件 - 找不到文件 - Android write to file - can't find file 无法从手机内部存储器中的数据文件夹或文档文件夹中读取文本文件 - Can't read text file from the data folder or documents folder in the phone's internal storage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM