安卓文件路径

安卓文件路径

默认的权限只能存取自己应用的文档目录,不能存取外部的存储空间的。

Delphi有一个System.IOUtils单元,

里面有一个TPath,是一个跨平台的路径操作结构体,

里面有获取常用路径的静态方法(不需要创建直接可以调用的方法)。

 

因为通常情况下,我们开发的应用会先在Windows平台下进行测试,

所以先来看一下这些方法在Windows平台下都指向哪些目录:

GetHomePath:

C:\Users\ggggcexx\AppData\Roaming

 

GetDocumentsPath:

C:\Users\ggggcexx\Documents

 

GetSharedDocumentsPath:

C:\Users\Public\Documents

 

GetLibraryPath:

C:\MyFiles\OrangeUIProduct\项目名称\APP\Win32\Debug\

 

GetCachePath:

C:\Users\ggggcexx\AppData\Local

 

GetPublicPath:

C:\ProgramData

 

GetPicturesPath:

C:\Users\ggggcexx\Pictures

 

GetSharedPicturesPath:

C:\Users\Public\Pictures

 

GetCameraPath:

C:\Users\ggggcexx\Pictures

 

GetSharedCameraPath:

C:\Users\Public\Pictures

 

GetDownloadsPath:

C:\Users\ggggcexx\Downloads

 

GetSharedDownloadsPath:

C:\Users\Public\Downloads

 

 

再来看下安卓平台下面都指定哪些目录,

GetHomePath:

/data/user/0/com.embarcadero.FirstAidExpert_FMX_D11/files

 

GetDocumentsPath:

/data/user/0/com.embarcadero.FirstAidExpert_FMX_D11/files

 

GetSharedDocumentsPath:

/storage/emulated/0/Documents

 

GetLibraryPath:

/data/app/com.embarcadero.FirstAidExpert_FMX_D11-wlgPkLmXf6nZlWnaSyFsnw==/lib/arm

 

GetCachePath:

/data/user/0/com.embarcadero.FirstAidExpert_FMX_D11/cache

 

GetPublicPath:

/storage/emulated/0/Android/data/com.embarcadero.FirstAidExpert_FMX_D11/files

 

GetPicturesPath:

/storage/emulated/0/Android/data/com.embarcadero.FirstAidExpert_FMX_D11/files/Pictures

 

GetSharedPicturesPath:

/storage/emulated/0/Pictures

 

GetCameraPath:

/storage/emulated/0/Android/data/com.embarcadero.FirstAidExpert_FMX_D11/files/DCIM

 

GetSharedCameraPath:

/storage/emulated/0/DCIM

 

GetDownloadsPath:

/storage/emulated/0/Android/data/com.embarcadero.FirstAidExpert_FMX_D11/files/Download

 

GetSharedDownloadsPath:

/storage/emulated/0/Download

 

其中,

GetDocumentsPath就是应用的文档目录(私有存储空间),

如果你要保存文件,一般将文件保存在文档目录。

在Android下,GetHomePath和GetDocumentsPath都指向同一个目录

 

GetCachePath是缓存目录,可以保存比如临时下载的网络图片,

手机上的清除应用缓存就是清理的这个目录。

 

还有一些带Shared的目录,

GetSharedDocumentsPath、GetSharedPicturesPath、GetSharedCameraPath、GetSharedDownloadsPath,

这些则是可以与其它应用共享的目录,都保存在外部存储空间中,

其他应用可以访问到它们。

 

 

路径分隔符

需要注意的是,安卓系统下面路径分隔符和Windows下不一样,

Windows下是\,Anroid下面是/,

那么我们平时写代码要拼路径的时候,该怎么办呢?

Delphi已经帮我们考虑好了,

大家统一用常量PathDelim即可。

比如你要将当前登录用户的账号密码保存到Config.ini中,

那么你就可以通过TPath.GetDocumentsPath+PathDelim+’Config.ini’来访问它。

 
posted @   delphi中间件  阅读(520)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2020-12-21 咏南中间件(datasnap)新接口演示
2018-12-21 mormot支持https
2015-12-21 DELPHI7加载UNICODE编码格式的TXT显示为乱码的解决方法
2013-12-21 冬至
点击右上角即可分享
微信分享提示