android获取各种系统路径的方法

来源:互联网 发布:wto国际贸易统计数据库 编辑:程序博客网 时间:2024/06/05 01:12

Android获取各种系统路径的方法

转载路径:点击打开链接


通过Environment获取的

Environment.getDataDirectory().getPath() :                                      获得根目录/data 内部存储路径
Environment.getDownloadCacheDirectory().getPath()  :               获得缓存目录/cache
Environment.getExternalStorageDirectory().getPath():                  获得SD卡目录/mnt/sdcard(获取的是手机外置sd卡的路径)
Environment.getRootDirectory().getPath() :                                     获得系统目录/system

通过Context获取的


Context.getDatabasePath()                                                      返回通过Context.openOrCreateDatabase 创建的数据库文件
Context.getCacheDir().getPath() :                                            用于获取APP的cache目录 /data/data/<application package>/cache目录
Context.getExternalCacheDir().getPath()  :                           用于获取APP的在SD卡中的cache目录/mnt/sdcard/android/data/<application package>/cache
Context.getFilesDir().getPath()  :                                             用于获取APP的files目录 /data/data/<application package>/files
Context.getObbDir().getPath():                                                用于获取APPSDK中的obb目录 /mnt/sdcard/Android/obb/<application package>
Context.getPackageName() :                                                  用于获取APP的所在包目录
Context.getPackageCodePath()  :                                          来获得当前应用程序对应的 apk 文件的路径
Context.getPackageResourcePath() :                                   获取该程序的安装包路径



android系统可通过Environment.getExternalStorageDirectory()获取存储卡的路径,但是现在有很多手机内置有一个存储空间,同时还支持外置sd卡插入,这样通过Environment.getExternalStorageDirectory()方法获取到的就是内置存储卡的位置,需要获取外置存储卡的路径就比较麻烦,这里借鉴网上的代码,稍作修改,在已有的手机上做了测试,效果还可以,当然也许还有其他的一些奇葩机型没有覆盖到。

原创粉丝点击