内部:
Context.getFilesDir() :data/data/packageName/file
Context.getCacheDir() : data/data/packageName/cache
Context.getDir(String name, int mode) : data/data/packageName/ + name
mode: @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
default operation, {@link #MODE_WORLD_READABLE} and
{@link #MODE_WORLD_WRITEABLE} to control permissions.
context.getDatabasePath(String name) : /data/data/com.example.qymh/databases/name.db
context.getPackageCodePath() : /data/app/xxx.apk ?
context.getPackageResourcePath():/data/app/xxx.apk ?
-----------------------------
首先在xml配置sdcard读写权限。
sdcard的,但不需要动态申请权限,卸载会被清除,任何人都可以访问,可以用来设置app升级下载路径
context.getExternalCacheDir() : /storage/emulated/0/Android/data/packageName/cache
context.getExternalFilesDir("") : /storage/emulated/0/Android/data/packageName/files
context.getObbDir : /storage/emulated/0/Android/obb/packageName
自定义目录,需要动态申请权限
String parent = getExternalCacheDir().getParent();
File file = new File(parent + name);
file.mkdirs();
-----------------------------
sd卡,需要动态申请
Environment.getExternalStorageDirectory():/storage/emulated/0
sd卡公共目录
Environment.getExternalStoragePublicDirectory(type)
DIRECTORY_MUSIC:/storage/emulated/0/Music
DIRECTORY_PODCASTS:/storage/emulated/0/Podcasts
DIRECTORY_RINGTONES:/storage/emulated/0/Ringtones
DIRECTORY_ALARMS:/storage/emulated/0/Alarms
DIRECTORY_NOTIFICATIONS:/storage/emulated/0/Notifications
DIRECTORY_PICTURES:/storage/emulated/0/Pictures
DIRECTORY_MOVIES:/storage/emulated/0/Movies
DIRECTORY_DOWNLOADS:/storage/emulated/0/Downloads
DIRECTORY_DCIM:/storage/emulated/0/Dcim
DIRECTORY_DOCUMENTS:/storage/emulated/0/Documents
-----------------------------
其他:
Environment.getDataDirectory(); /data
Environment.getDownloadCacheDirectory(); /cache
Environment.getRootDirectory(); /system