[英]Cannot read a file from Downloads folder on Android
I have text files with a custom extension.我有带有自定义扩展名的文本文件。 I have deployed one with my Delphi FMX application to the Documents folder, and this one loads fine using TStringList.LoadFromFile(Path)
.我已经将我的 Delphi FMX 应用程序部署到 Documents 文件夹中,并且使用TStringList.LoadFromFile(Path)
可以正常加载。 The path is:路径是:
/data/user/0/com.embarcadero.[appname]/files/[filename]
I then try to load a file from the following path:然后我尝试从以下路径加载文件:
/storage/emulated/0/Download/[filename]
FileExists(Path)
returns true, indicating that the file does exist. FileExists(Path)
返回 true,表示文件确实存在。 However, it fails in TStringList.LoadFromFile(Path)
.但是,它在TStringList.LoadFromFile(Path)
中失败。
I assume that this is some permissions issue.我认为这是一些权限问题。 However, I have checked that 'Read external storage' is enabled in the Delphi project options under 'Uses Permissions', so the manifest should have that included.但是,我已经在“使用权限”下的 Delphi 项目选项中检查了“读取外部存储”是否已启用,因此清单应该包含它。 Are there any other permission settings required for this location?此位置是否需要任何其他权限设置?
Note that I'm testing on a Huawei P10 with Android 8.请注意,我正在使用 Android 8 在华为 P10 上进行测试。
The files load after using PermissionService.RequestPermissions for ReadExternalStorage, as per the Object Pascal/Mobile Snippets/CameraRoll sample.根据 Object Pascal/Mobile Snippets/CameraRoll 示例,在对 ReadExternalStorage 使用 PermissionService.RequestPermissions 后加载文件。
{$IF DEFINED (ANDROID)}
var FStorage := '/storage/emulated/0/RAH Download';
{$ELSEIF DEFINED (MSWINDOWS)}
var FStorage := ExpandFileName(GetCurrentDir) + PathDelim + 'Download';
{$ELSE}
ShowMessage('Not Support';
Exit;
{$ENDIF}
if not DirectoryExists(FStorage) then begin
if not CreateDir(FStorage) then
Exit;
end;
=========================================================== ==================================================== =========
var HTTP := TNetHTTPClient.Create(nil);
try
var Stream := TMemoryStream.Create;
try
HTTP.Get(FURL, Stream);
Stream.SaveToFile(FStorage + Pathdelime + 'FileName');
finally
Stream.DisposeOf;
end;
finally
HTTP.DisposeOf;
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.