android|android 几个路径的获取

getPackageResourcePath获取获取该程序的安装包路径 【android|android 几个路径的获取】String appPath = getApplicationContext().getPackageResourcePath();
/data/app/com.younghare.lepusService-2/base.apk
getFilesDir getApplicationContext().getFilesDir()
android|android 几个路径的获取
文章图片
image.png getApplicationContext().getFilesDir().getParent()
其实就是/data/data/包(这是沙盒其他app无法访问)
String dataAppPath = getApplicationContext().getFilesDir().getParent();
new File(dataAppPath+"/databases/task.db").exists(); //返回是true
android|android 几个路径的获取
文章图片
image.png getFilesDir().getAbsolutePath() 抽象路径名的绝对路径名字符串
String appAbsolute = getApplicationContext().getFilesDir().getAbsolutePath()
/data/user/0/com.younghare.lepusService/files
getCacheDir() 获取CachDir
getApplicationContext().getCacheDir()

android|android 几个路径的获取
文章图片
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文件夹,我们可以指定子文件夹
android|android 几个路径的获取
文章图片
image.png android|android 几个路径的获取
文章图片
image.png

    推荐阅读