Android APK路径总结
Android开发过程能够会经常用到各种路径.本文整理相关路径汇总.
getPackageResourcePath获取获取该程序的安装包路径
String appPath = getApplicationContext().getPackageResourcePath();
/data/app/com.demo.test/base.apk
getFilesDir
getApplicationContext().getFilesDir()
getApplicationContext().getFilesDir().getParent()
//其实就是/data/data/包(package独有, 非root不可访问)
String dataAppPath = getApplicationContext().getFilesDir().getParent();
new File(dataAppPath+"/databases/task.db").exists();//返回是true
getFilesDir().getAbsolutePath()
抽象路径名的绝对路径名字符串
String appAbsolute = getApplicationContext().getFilesDir().getAbsolutePath()
/data/user/0/com.demo.test/files
getCacheDir()
获取CachDir
getApplicationContext().getCacheDir()
//data/data/package/cache
getExternalCacheDir
通过Context.getExternalCacheDir()方法可以获取到sdcard/android/data/你的应用包名/cache/目录,一般存放临时缓存数据
getApplicationContext().getExternalCacheDir()
/storage/emulated/0/Android/data/com.package.name/cache
getExternalFilesDir
getExternalFilesDir(null)参数传入的为null,这样默认访问的是files文件夹,我们可以指定子文件夹
getExternalFilesDir(null);
getExternalFilesDir(String);