Specific explanations of file folders related to Android apps

Source: Internet
Author: User

First, the method is introduced:

Each Android application has the ability to get the application-related folders through the context, which are functionally different and each folder has its own characteristics. Sometimes confusing, this article combines Android source code gaze and actual operation. Give a detailed description of each method:

Method:Getfilesdir

Explanation: returns the absolute path to the file system created and stored by Context.openfileoutput (), application files, which are deleted when the program is uninstalled.


Method:Getcachedir

Explanation: Returns the application-specified cache folder, which is removed when the device is out of memory, so files stored here are not guaranteed and may be discarded at any time.


Method:Getdir

Explanation: This is a file that can store your own application's own definition. You can create or access this folder by using the file instance returned by this method. Note that the files under this folder are only available for your own program to access.


Method:Getexternalcachedir

Interpretation: Use this method to write permissions for external storage "<uses-permission android:name=" Android.permission.WRITE_EXTERNAL_STORAGE "/>", Calling this method returns the absolute path of the application's external file system (Environment.getexternalstoragedirectory ()) folder, which is the cache file used to hold the app. It is the same as the Getcachedir folder. Files under the folder will be erased when the program is uninstalled.


Method:Getexternalfilesdir

Interpretation: Use this method to write permissions for external storage "<uses-permission android:name=" Android.permission.WRITE_EXTERNAL_STORAGE "/ > ", this folder is an external file system associated with the application, it is not the same as Getexternalcachedir is only to have the application exists it will always exist, these files belong to your application only. Cannot be interviewed by other people.

Same. Files under this folder will also be deleted when the program is uninstalled.


Method:Getexternalfilesdir

interpretation: as in the above method, just the return is a file of a certain type under its folder, these types can be:
Environment#directory_music Music
Environment#directory_podcasts Audio
Environment#directory_ringtones Ringtones
Environment#directory_alarms Alarm
Environment#directory_notifications notification ringtone
environment#directory_pictures Pictures
Environment#directory_movies Video


Method:Getdatabasepath

Explanation: Saving a database file created through Context.openorcreatedatabase


Method:Getpackagecodepath

Explanation: returns the full path to the Android installation package, which is a zip archive that contains the application code and the assets file.


Method:Getpackageresourcepath

Explanation: Returns the full path of the Android installation package. This package is a zip file to lock. It contains the private resources of the application.


Method:Getobbdir

Explanation: return to the application's Obb file folder (if any), note that the application does not have any OBB files whatsoever. This folder does not exist.


Second, test procedure:

Test code such as the following:

Private StringBuilder GetFilePath () {StringBuilder filepathbuilder = new StringBuilder ();//return via Context.openfileoutput () Create and store an absolute path to the file system, application files. These files will be erased when the program is uninstalled.

Filepathbuilder.append ("Getfilesdir = ="). Append (Getfilesdir ()). Append ("\ n");//Returns the cache folder specified by the application. These files are first removed when the device is out of memory, so the files stored here are not guaranteed. may be discarded at any time. Filepathbuilder.append ("Getcachedir = ="). Append (Getcachedir ()). Append ("\ n");//This is a file that can store your own application definition, You can create or access this folder by using the file instance returned by this method, noting that the files under that folder are only available to your own program. Filepathbuilder.append ("Getdir = ="). Append (Getdir ("Test.txt", context.mode_world_writeable)). Append ("\ n");/* Need to write file permissions <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> */// Calling this method returns the absolute path to the application's external file system (Environment.getexternalstoragedirectory ()) folder, which is the cache file used to hold the app. It is the same as the Getcachedir folder. Files under the folder will be erased when the program is uninstalled.

Filepathbuilder.append ("Getexternalcachedir = ="). Append (Getexternalcachedir ()). Append ("\ n");// This folder is an external file system associated with the application, and unlike Getexternalcachedir, it will persist only if the application exists. These files belong only to your application and cannot be interviewed by others.

Same, files under this folder are also deleted when the program is uninstalled. Filepathbuilder.append ("Getexternalfilesdir = ="). Append (Getexternalfilesdir ("\")). Append ("\ n");/** * Like the above method, just Returns a file of a certain type under its folder, which can be: * Environment#directory_music music * environment#directory_podcasts Audio * Environment#direc Tory_ringtones Ringtones * environment#directory_alarms alarm * environment#directory_notifications notification ringtone * Environment# Directory_pictures picture * environment#directory_movies Video * * */filepathbuilder.append ("Getexternalfilesdir = ="). App End (Getexternalfilesdir (Environment.directory_pictures)). Append ("\ n");//Save through Context.openorcreatedatabase The database file created by Filepathbuilder.append ("Getdatabasepath = ="). Append (Getdatabasepath (Data_base_name)). Append ("\ n");//Return a Ndroid the full path of the installation package, which is a zip-compressed file that contains the application code and the assets file Filepathbuilder.append ("Getpackagecodepath = ="). Append ( Getpackagecodepath ()). Append ("\ n");//returns the full path of the Android installation package, which is a zip-to-lock file that contains the application's private resources.

Filepathbuilder.append ("Getpackageresourcepath = ="). Append (Getpackageresourcepath ()). Append ("\ n");// Return to the application's Obb file folder (if any), note that the application does not exist regardless of the Obb file. Filepathbuilder.append ("Getobbdir = ="). Append (Getobbdir ()). Append ("\ n"); return filepathbuilder;}


test results such as the following:



Specific explanations of file folders related to Android apps

Related Article

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.