The access and function parsing of Android application-related directories---full

Source: Internet
Author: User

Android application basic need to carry out the file to save work, always need the time from the Internet casually search, but did not do a summary, today can not be dragged, to do a summary!

Very basic things, small white one, sincerely hope to help everyone, the wrong place everybody pointing

The file read problem I met generally has these: where is the file saved? And how to consider the related functions, directory permissions issues? And the question of whether the directory will be deleted after the app is deleted?

There are three common paths for storage:

For example, the name of the application is called Com.android.framework

1./data/data/package_name/
This directory is only visible to the app, and if the phone does not have root, with the ADB also can not see this directory, the directory used to store and apply the cycle-related files, will be removed with the application of the uninstall

/data/data/com.android.framework/shared_prefs/is used to store sharedpreference

/data/data/com.android.framework/databases/is used to store database DB, related functions and Getdatabasepath ()

/data/data/com.android.framework/app_webview and/data/data/package_name/xxxwebviewcachexxx Used to store caches and cookies generated by the app's built-in WebView, which may vary depending on the name and location of the Android version
/data/data/com.android.framework/lib used to store the. So static library file for the app
/data/data/com.android.framework/cache the directory can use functionsGetcachedir ()Get
/data/data/com.android.framework/files the directory can use functionsGetfilesdir ()GET,openfileinput ()and theopenfileoutput ()The function also operates the file under the directory,fileList ()function is used to list all files in this directory,DeleteFile (String name)Used to delete files in this file directory
/data/data/com.android.framework/This directory can of course create a subset of directories, using the method isGetdir (String name, int mode), name in the parameter is the subdirectory name that needs to be created under that directory.

If you can open the directory for your app, you'll typically see a lot of subdirectories in that directory
Note: The above function is not explicitly specified by using the context call

Ps:
There is also a particularly strange function, inadvertently seen by the getcodecachedir () function, the interpretation of this function is the optimal for storing compiled or optimized code Generated by your application at runtime, this directory is suitable for the runtime to store the application generated by the compilation or optimization of the code, but I called the nosuchmethoderror, forgot to enlighten ~ ~

There are other related functions.

Getpackagecodepath () =/data/app/com.android.framework-1.apk
Getpackageresourcepath () =/data/app/com.android.framework-1.apk


2. Two sub-directories in SD card Android directory
Note: The directory is mounted under the SD card, so when the SD is not available, both directories are invalid, and the same application cycle related files will be removed along with the application's uninstallation

Note requires permission <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>

(1) android/data/package_name/

android/data/com.android.framework/files/The directory is available Getexternalfilesdir (String type) and getexternalfilesdirs (string type) gets, the parameter type is the subdirectory name, and null is the root directory, which is automatically generated after the call

android/data/com.android.framework/Cache/This directory is available Getexternalcachedir () and getexternalcachedirs () GET,This directory is automatically generated after the latter call

(2) android/obb/package_name/(Obb directory may also not exist), original: Note If the application does not has any OBB files, this directory might not Exi St


the directory's correlation function is only two simple:getobbdirs () and getobbdir (), which is automatically generated after the call , the directory is usually the game's packet directory

3. A file directory that is customized under SD card

In addition to the top two directories, of course, can also be in the SD card custom directory, generally used for permanent storage, uninstall the application will not be deleted, the relevant functions are as follows

environment.getexternalstoragestate (), this function is used to obtain the Mount State of the SD card, if the incoming parameter path is to obtain the mount State of the path, such as the directory is mounted by the user's PC, or removed from the device, or other problems occur, the return of the state is not the same
environment.getexternalstoragedirectory (), this function is used to return the root directory of the SD card, namely,/storage/emulated/0/, do not create files under the root directory, strongly create a subdirectory to operate, otherwise it will contaminate the SD card's home directory, there is a section of the function is an it is a filesystem that Can hold a relatively large amount of data and which is gkfx across all applications (does not enforce permissions), the directory all Apps are operational, for shared directories
environment.getdownloadcachedirectory () , which is used to return to the download cache directory below the SD card
environment.getdatadirectory () that is used to get the user's data directory
environment.getexternalstoragepublicdirectory (String type) , the function is used to return the relevant directory according to the type, some variables of type environment, the passed-in type parameter cannot be null, the returned directory path may not exist, so it must be confirmed before use, do not create the directory
environment.getrootdirectory (), which is used to return the root system directory and mount only as read-only
Finally, the code for all the directories returns the results tested as follows
L.E ("Getdatabasepath ():" +getdatabasepath ("student.db")); L.E ("Getcachedir ():" +getcachedir ()); L.E ("Getfilesdir ():" + Getfilesdir ()); String[] strings = FileList ();//Is empty for (String path:strings) {L.E ("fileList ():---" + path);} L.E ("Getdir (\" zhao\ "):" + getdir ("Zhao", mode_private));//L.E ("Getcodecachedir ():" + Getcodecachedir ()); JAVA.LANG.NOSUCHMETHODERRORL.E ("Getpackagecodepath ():" + Getpackagecodepath ()); L.E ("Getpackageresourcepath ():" + Getpackageresourcepath ()); L.E ("Getexternalfilesdir ():" + getexternalfilesdir (null)); file[] paths = Getexternalfilesdirs (null), for (File path:paths) {L.E ("getexternalfilesdirs ():---" + path.getpath ());} L.E ("Getexternalcachedir ():" + Getexternalcachedir ());p aths = Getexternalcachedirs (); for (File path:paths) {L.e ("GetE Xternalcachedirs ():---"+ path.getpath ());} paths = Getobbdirs (); for (File path:paths) {L.E ("getobbdirs ():---" + path.getpath ());} L.E ("Environment.getexternalstoragestate ():" + environment.getexternalstoragestate ()); L. E ("Environment.getexternalstoragedirectory ():" +environment.getexternalstoragedirectory ()); L.E ("Environment.getdownloadcachedirectory ():" +environment.getdownloadcachedirectory ()); L.E ("Environment.getexternalstoragepublicdirectory (environment.directory_music):" + Environment.getexternalstoragepublicdirectory (Environment.directory_music)); L.E ("Environment.getrootdirectory ():" +environment.getrootdirectory ());


E/com.android.framework:getdatabasepath ():/data/data/com.android.framework/databases/student.dbe/ Com.android.framework:getCacheDir ():/data/data/com.android.framework/cachee/com.android.framework:getfilesdir ( ):/data/data/com.android.framework/filese/com.android.framework:getdir ("Zhao"):/data/data/ Com.android.framework/app_zhaoe/com.android.framework:getpackagecodepath ():/data/app/ Com.android.framework-1.apke/com.android.framework:getpackageresourcepath ():/data/app/ Com.android.framework-1.apke/com.android.framework:getexternalfilesdir ():/storage/emulated/0/android/data/ Com.android.framework/filese/com.android.framework:getexternalfilesdirs ():---/storage/emulated/0/android/data/ Com.android.framework/filese/com.android.framework:getexternalcachedir ():/storage/emulated/0/android/data/ Com.android.framework/cachee/com.android.framework:getexternalcachedirs ():---/storage/emulated/0/android/data/ Com.android.framework/cachee/com.android.framework:getobbdirs ():---/storage/emulated/0/anDroid/obb/com.android.frameworke/com.android.framework:environment.getexternalstoragestate (): mountedE/ Com.android.framework:Environment.getExternalStorageDirectory ():/storage/emulated/0e/com.android.framework: Environment.getdownloadcachedirectory ():/cachee/com.android.framework: Environment.getexternalstoragepublicdirectory (environment.directory_music):/storage/emulated/0/musice/ Com.android.framework:Environment.getRootDirectory ():/system


                                                                                                                                                                                                                                                             

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The access and function parsing of Android application-related directories---full

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.