Android path problem

Android development: which folder is the filePath placed in

Environment.getDataDirectory() = /data
Environment.getDownloadCacheDirectory() = /cache
Environment.getExternalStorageDirectory() = /mnt/sdcard
Environment.getExternalStoragePublicDirectory(“test”) = /mnt/sdcard/test
Environment.getRootDirectory() = /system
getPackageCodePath () = /data/app/com.my.app-1.apk
getPackageResourcePath() = /data/app/com.my.app-1.apk
getCacheDir() = /data/data/com.my.app/ cache
getDatabasePath("test") = /data/data/com.my.app/databases/test
getDir("test", Context.MODE_PRIVATE) = /data/data/com.my.app/app_test
getExternalCacheDir() = / mnt/sdcard/Android/data/com.my.app/cache
getExternalFilesDir(“test”) = /mnt/sdcard/Android/data/com.my.app/files/test
getExternalFilesDir(null) = /mnt/sdcard/Android/data/com.my.app/files
getFilesDir() = /data/data/com.my.app/files

 

public String getDiskCacheDir(Context context) {  
    String cachePath = null;  
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())  
            || !Environment.isExternalStorageRemovable()) {  
        cachePath = context.getExternalCacheDir().getPath();  
    } else {  
        cachePath = context.getCacheDir().getPath();  
    }  
    return cachePath;  
}  

It can be seen that when the SD card exists or the SD card cannot be removed, the getExternalCacheDir() method is called to obtain the cache path, otherwise the getCacheDir() method is called to obtain the cache path. The former gets the path /sdcard/Android/data/<application package>/cache, while the latter gets the path /data/data/<application package>/cache.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326070459&siteId=291194637