德尔福XE5 Android的 - 存储路径问题 [英] Delphi XE5 Android - Storage path problems

查看:591
本文介绍了德尔福XE5 Android的 - 存储路径问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始做了在Delphi XE5一个android的应用程序,并遇到了一些麻烦。

I started doing an app for android in Delphi XE5, and encountered some troubles.

我真不明白有关获取路径。
当我设置权限写入和读取外部存储,我试图让道,所以我能看到,我已把我创建的文件,这是我所得到的:

I really don't understand about getting paths. After I set the permissions to Write and Read External storage, I tried to get paths so I can see where I'm saving files I create, and this is what I get:

有关System.IOUtils.TPath。 - >

for System.IOUtils.TPath. ->

GetDocumentsPath;       -  /data/data/com.myapp.app1/files
GetDownloadsPath;       -  /storage/emulated/0/Android/data/com.myapp.app1/files/Download
GetHomePath;            -  /data/data/com.myapp.app1/files
GetSharedDocumentsPath; -  /storage/emulated/0/Android/data/com.myapp.app1/files
GetLibraryPath;         -  /data/data/com.myapp.app1/files
GetPublicPath;          -  /storage/emulated/0/Android/data/com.myapp.app1/files
GetPicturesPath;        -  /storage/emulated/0/Android/data/com.myapp.app1/files/Pictures

据我从其他主题了解,GetDocumentsPath应该是默认的SD卡路径,下载应SD卡/下载,而是它使用/ Android的/数据/应用程序文件夹/文件/在这里及牡丹它已经存在于SD卡的文件夹本身。

As far as I understood from other topics, the GetDocumentsPath should be default sdcard path, Downloads should be sdcard/Downloads, but instead it's using /Android/data/application's folder/files/ here creats folders which already exists on the sdcard itself.

/模拟/ 0 /其实是一样的/ SD卡/我的手机上,如果这是任何人(以防万一......)。混乱

/emulated/0/ is actually the same as /sdcard/ on my phone, if that's confusing for anyone (just in case....).

它有几个快捷键,因为据我所知,存储/模拟/ 0 /,存储/ sdcard0 /,也是从根的文件夹直接访问到SD卡/(但我猜的应用程序没有root权限是唯一的默认访问存储/文件夹,因此存储/ sdcard0和模拟/ 0文件夹是否存在;不知道为什么被复制快捷方式到同一文件夹,虽然....)

It has several shortcuts, as far as I understand, storage/emulated/0/, storage/sdcard0/, also from root's folder is directly access to sdcard/ (but I guess the apps without root access has only default access to storage/ folder, hence the storage/sdcard0 and emulated/0 folders exists; don't know why are duplicated shortcuts to the same folder, though....)

[还有存储/模拟/遗产/,这也似乎指向同一个文件夹,但我从来没有接触它,因为我曾经有过一些麻烦与文件副本和奇怪的音乐库中的行为,我扎根权利之前并格式化它。从来没有想通到底发生了什么,但甚至不关心。事实是,仿真文件夹似乎是邪恶和原因不明;)]

[[ There's also storage/emulated/legacy/, which also seems to point to the same folder, but I never touch it, since I used to have some troubles with file duplicates and strange Music library behaviour, right before I rooted and formatted it. Never figured what really happened, but don't even care. Fact is, that the emulated folder seems to be evil and unexplained ;) ]]

另外,有相关的事实,这些路径的麻烦,该手机没有安装选项,但只有MTP,或者说,它的Andr​​oid 4.3,还是....?

Also, are these path troubles related to the fact, that the phone has no mount option, but only MTP, or that it's android 4.3, or....?

感谢。

//更新:关于裂解的问题,这和屏幕分辨率为入佛门先生建议

// Update: Splitted questions about this and screen resolutions as Sir Rufo suggested.

更新:
貌似硬编码/sdcard/filename.extension为路径字符串做工作,但我不知道它是多么明智的铁杆应用中的位置...://

UPDATE: Looks like hardcoding '/sdcard/filename.extension' as path string does the job, however I'm not sure how wise it is to hardcore the location in the app... ://

推荐答案

不着​​急code的路径。到外部存储的路径可能为不同的Andr​​oid平台各不相同,你会错过跨平台编程的优势。当我开始编程为Android我写了一个小的应用程序去哪儿针对列出所有特殊目录适用于所有平台。这是非常有用的,因为我不知道这些目录甚至是Windows,更不用说Android系统。在你的榜样,你错过了SharedDirectories。这将返回的路径, /存储/模拟/ 0 /音乐/ GetSharedMusicPath 例如,等了电影下载,等等。我认为这是对我的Galaxy Tab的不同,但我不知道。只是删除姓氏和你有路径到外部存储器。

Try not to hard code the path. The paths to external storage may vary for different Android platforms and you'll miss the advantage of cross-platform programming. When I started programming for Android I wrote a small App 'Where' targeted at listing all 'special' directories for all platforms. That was very useful as I didn't know these directories for even Windows, let alone Android. In your example you miss the SharedDirectories. This will return the path to /storage/emulated/0/Music/ for GetSharedMusicPath for example, and so on for Movies, Download, etc. I thought it was different for my Galaxy Tab but I'm not sure. Just remove the last name and you have the path to external storage.

请小心,有 READ_EXTERNAL_STORAG​​E WRITE_EXTERNAL_STORAG​​E 如果你想读取和写入到外部存储设置(在项目的某个地方|选项| Android版)。我不知道是否Android版可以让你在外部存储根写,你必须尝试自己。

Take care that you have READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE set if you want to read and write to your external storage (somewhere in Project | Options | Android). I don't know whether Android allows you to write in the external storage root, you must try that yourself.

uses System.IOUtils;

procedure THeaderFooterForm.Loaded;
begin
   inherited Loaded;

   TPath.SetApplicationPath ('WhereAppTest');

   add_path (TPath.GetTempPath, 'GetTempPath');
   add_path (TPath.GetHomePath, 'GetHomePath');
   add_path (TPath.GetDocumentsPath, 'GetDocumentsPath');
   add_path (TPath.GetApplicationPath ('WhereAppTest'), 'GetApplicationPath');
   add_path (TPath.GetSharedDocumentsPath, 'GetSharedDocumentsPath');
   add_path (TPath.GetLibraryPath, 'GetLibraryPath');
   add_path (TPath.GetCachePath, 'GetCachePath');
   add_path (TPath.GetPublicPath, 'GetPublicPath');
   add_path (TPath.GetPicturesPath, 'GetPicturesPath');
   add_path (TPath.GetSharedPicturesPath, 'GetSharedPicturesPath');
   add_path (TPath.GetCameraPath, 'GetCameraPath');
   add_path (TPath.GetSharedCameraPath, 'GetSharedCameraPath');
   add_path (TPath.GetMusicPath, 'GetMusicPath');
   add_path (TPath.GetSharedMusicPath, 'GetSharedMusicPath');
   add_path (TPath.GetMoviesPath, 'GetMoviesPath');
   add_path (TPath.GetSharedMoviesPath, 'GetSharedMoviesPath');
   add_path (TPath.GetAlarmsPath, 'GetAlarmsPath');
   add_path (TPath.GetSharedAlarmsPath, 'GetSharedAlarmsPath');
   add_path (TPath.GetDownloadsPath, 'GetDownloadsPath');
   add_path (TPath.GetSharedDownloadsPath, 'GetSharedDownloadsPath');
   add_path (TPath.GetRingtonesPath.Empty, 'GetRingtonesPath');
   add_path (TPath.GetSharedRingtonesPath, 'GetSharedRingtonesPath');
   FMediaPlayer := TMediaPlayer.Create(Self);
end; // Loaded //

procedure THeaderFooterForm.add_path (path, header: string);
var
   item: TListViewItem;
   bitmap: TBitmap;
begin
   item := List_Paths.Items.Add;
   item.ButtonText := 'button';
   item.Detail := path;
   item.Text := header;
end; // add_path //

这篇关于德尔福XE5 Android的 - 存储路径问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆