【发布时间】:2019-07-30 22:27:25
【问题描述】:
在我的代码中,我创建了一个 .TXT 文件并将其存储在共享文件夹“下载”中,如下所示:
procedure TF_start.Button2Click(Sender: TObject);
var
path_file output_text: string;
begin
path_file := TPath.Combine(System.IOUtils.TPath.GetSharedDownloadsPath, 'Folder_app');
output_text := 'test';
if not TDirectory.Exists(path_file) then
TDirectory.CreateDirectory(path_file);
try
TFile.WriteAllText(TPath.Combine(path_file, Nome_Arquivo), Arquivo_saida);
except
ShowMessage('An error occurred while saving the file.');
end;
end;
该文件已完美创建,但 Android 本身在索引文件时存在问题,因此可以通过 Windows 资源管理器读取它们,因此您必须重新扫描创建该文件的文件夹以使其可见。 PlayStore 上甚至有一些应用程序会重新扫描整个 sdcard,但要求我的客户安装辅助文件以使用我的应用程序并不是一个好的选择...
我找到了一个理论上在特定文件夹上执行重新扫描的代码,但它不起作用。没有错误,但文件夹和文件 continue 在 Windows 资源管理器中不可见... 代码是这样的:
procedure TF_corrida.BTNfinalize_appClick(Sender: TObject);
var
c: Integer;
JMediaScannerCon: Androidapi.Jni.Media.JMediaScannerConnection;
JMediaScannerCon_Client: Androidapi.Jni.Media.JMediaScannerConnection_MediaScannerConnectionClient;
begin
JMediaScannerCon:=TJMediaScannerConnection.JavaClass.init(TAndroidHelper.Context, JMediaScannerCon_Client);
JMediaScannerCon.connect;
c:=0;
while not JMediaScannerCon.isConnected do begin
Sleep(100);
inc(c);
if (c>20) then break;
end;
if (JMediaScannerCon.isConnected) then begin
JMediaScannerCon.scanFile(StringToJString(path_file), nil);
JMediaScannerCon.disconnect;
end;
end;
有谁知道为什么这段代码不起作用?我什至发现它在 Delphi Tokyo 中不起作用,但我正在使用 Delphi Rio。
是的,我在我的代码中正确地说明了 READ 和 WRITE 存储权限。该文件已正确创建,只是不可见。
【问题讨论】:
标签: delphi firemonkey