0

我无法从电脑上查找并打开存储在手机上的文件。尽管这个答案有很好的解决方案,但我无法让它工作。我在 HTC Sensation Z710e 上运行

这是我要运行的代码:

function GetSDCardPath: string;
var MusicPathLength: integer;
    MusicPath, SDCardPath: string;
begin
 MusicPath:=System.IOUtils.TPath.GetSharedMusicPath;
 MusicPathLength:=Length(MusicPath);
 SDCardPath:=Copy(MusicPath, 0, MusicPathLength-5);
 Result:=SDCardPath;
end;

procedure TForm3.Button1Click(Sender: TObject);
var sr:TSearchRec;
begin
  CardPath:=TPath.Combine(GetSDCardPath,'*.*');

  if (FindFirst(CardPath,faNormal,sr)=0) then
  begin
    repeat
      Memo1.Lines.Add(sr.Name);
    until FindNext(sr)<>0;
    FindClose(sr);
  end;
end;

我用下面的代码做了第二次测试,当文件名出现在文件列表中时,我显然可以存储一个文件,但它似乎没有存储在 sdcard 上,至少不是作为我的外部驱动器 F 出现的那个:在我的电脑上。TPath.GetDocumentsPath 应该指向 sdcard,不是吗?

procedure TForm3.Button1Click(Sender: TObject);
var sr:TSearchRec;
begin
  CardPath:=TPath.Combine(TPath.GetDocumentsPath,'*.*');
  Memo1.Lines.Add(CardPath);

  if (FindFirst(CardPath,faAnyFile,sr)=0) then
  begin
    repeat
      Memo1.Lines.Add(sr.Name);
    until FindNext(sr)<>0;
    FindClose(sr);
  end;
end;

procedure TForm3.WriteClick(Sender: TObject);
var
  s: string;
  F:TextFile;
begin
  Memo1.Lines.Clear;
  s := TPath.Combine(TPath.GetDocumentsPath,'file2.txt');
  AssignFile(F,s);
  ReWrite(F);
  Writeln(F,'Test');
  CloseFile(F);
end;

首先我单击Write 按钮写入文件,然后单击Button1 列出目录中的文件。CardPath 是 /data/data/com.embarcadero.TestApp2/files/ 我有一个 Android/data/com.embarcadero.TestApp2/files/ 文件夹在我的电脑上可以看到,但那里没有文件。文件是否存储在我的设备内部?

4

1 回答 1

1

我终于找到了解决这个问题的方法。通过使用 TPath.GetSharedDocumentsPath,如果保存时设备未连接为驱动器,我可以在 pc 上看到从应用程序保存的文件(在此页面上提到)。Ei 使用该应用程序时,PC 不能同时将 sdcard 用作驱动器。

于 2014-06-26T06:06:11.140 回答