android|android 几个路径的获取
getPackageResourcePath获取获取该程序的安装包路径
【android|android 几个路径的获取】String appPath = getApplicationContext().getPackageResourcePath();
/data/app/com.younghare.lepusService-2/base.apk
getFilesDir
getApplicationContext().getFilesDir()
文章图片
image.png getApplicationContext().getFilesDir().getParent()
其实就是/data/data/包(这是沙盒其他app无法访问)
String dataAppPath = getApplicationContext().getFilesDir().getParent();
new File(dataAppPath+"/databases/task.db").exists();
//返回是true
文章图片
image.png getFilesDir().getAbsolutePath()
抽象路径名的绝对路径名字符串
String appAbsolute = getApplicationContext().getFilesDir().getAbsolutePath()
/data/user/0/com.younghare.lepusService/files
getCacheDir()
获取CachDir
getApplicationContext().getCacheDir()
文章图片
image.png getExternalCacheDir
通过Context.getExternalCacheDir()方法可以获取到 SDCard/android/data/你的应用包名/cache/目录,一般存放临时缓存数据
getApplicationContext().getExternalCacheDir()
/storage/emulated/0/Android/data/com.younghare.lepusService/cache
getExternalFilesDir
getExternalFilesDir(null)参数传入的为null,这样默认访问的是files文件夹,我们可以指定子文件夹
文章图片
image.png
文章图片
image.png
推荐阅读
- android第三方框架(五)ButterKnife
- Android中的AES加密-下
- 带有Hilt的Android上的依赖注入
- 唱歌教学(导致嗓音损坏的几个常见的错误唱歌方法!)
- android|android studio中ndk的使用
- 工具|后天就是七夕节,你准备好了吗(送上几个七夕代码,展示你技能的时候到了!)
- Android事件传递源码分析
- RxJava|RxJava 在Android项目中的使用(一)
- Android7.0|Android7.0 第三方应用无法访问私有库
- 深入理解|深入理解 Android 9.0 Crash 机制(二)