About android development and use of local memory, built-in memory cards and external memory cards

Source: Internet
Author: User

Android development and use of local memory, built-in memory cards and external memory cards ------------------------------------------ about android memory Introduction: android development often involves data caching, which requires us to understand the current memory usage of mobile phones, whether an external memory card exists. If yes, no built-in memory card is used. First, the mobile phone's local memory, including Rom and Ram. Rom: In android, Rom is equivalent to the system disk. When disk C is used, you need to obtain the root permission to use it. Generally, it can be divided into the body memory and internal storage (Samsung is mostly called: USB memory). The body memory includes partition directories such as system, data, and cache, by default, the software is installed with the body memory or internal storage card. Data (that is, the total number of mobile phone storage) + system (occupied by the mobile phone system) depends on the specific mobile phone number; Ram: equivalent to the running memory of the computer, run the storage. Not much explanation, that is, random runtime memory, and all power-off data disappears. External memory: Mobile Phone memory (TF card), equivalent to D, E, F and other hard disks. Choose ------------------------------------------ read mobile phone memory and external memory in android development. Android reads the body memory of the mobile phone memory. I have tried it again and again. I can import and read data to the data directory, but I need to obtain the root permission. This is a bit of a tangle, do anyone who wants to use the ** software go to root ?. Hey, so it is not recommended here. I will not paste the code here ........ the following is a small example of how Android reads files from the memory of a mobile phone. This is an important part of Android development, if we do not know how well, we can't read the data stored in the database. That is to say, every time we play games, our database is the most primitive data, this will cause us a lot of trouble. If this happens, your application is very bad. The Code is as follows: [java] view plaincopypublic static InputStream readInternalFileInputStream (Context context, String fileName) {/*** read the phone memory file **/try {FileInputStream FCM = context. openFileInput (fileName); return fe-;}catch (Exception e) {return null ;}} public static String readInternalFile (Context context, String fileName) {/*** read the phone memory file **/try {byte [] buffer = new byte [512]; int r Ead = 0; StringBuffer stringbuffer = new StringBuffer (); FileInputStream FCM = context. openFileInput (fileName); do {read = Fi. read (buffer); if (read> 0) stringbuffer. append (new String (buffer, 0, read, "UTF-8");} while (read! =-1); FCM. close (); return stringbuffer. toString ();} catch (Exception e) {return null;} external memory android reads an image from the sd card. 1 reads an image from the sd card. 1 obtains the permission to read the sd in AndroidMainfest. add [java] view plaincopy to the xml file <! -- Create and delete file permissions in SDCard --> <uses-permission android: name = "android. permission. MOUNT_UNMOUNT_FILESYSTEMS"> </uses-permission> <! -- Write data permission to SDCard --> <uses-permission android: name = "android. permission. WRITE_EXTERNAL_STORAGE "> </uses-permission> <uses-permission android: name =" android. permission. RESTART_PACKAGES "> </uses-permission> note: In <application...> </application> Add 2 to the front and find the directory of the SD card (in the case of a real machine)/*** image file path * print Environment. getExternalStorageDirectory (): "/mnt/sdcard", that is, the root directory of the SD card */[java] view plaincopypublic String filePath = Environm Ent. getExternalStorageDirectory () + "/client/tile/4240_0.jpg"; 3. Obtain the image by path [java] view plaincopyFile mfile = new File (path); if (mfile. exists () {// if the file contains Bitmap bm = BitmapFactory. decodeFile (path); return bm;} Note: when reading the image in the SD card, you can determine the value of Environment. getExternalStorageState () indicates whether the obtained path is successful. * If the obtained path is successful, the returned value is MEDIA_MOUNTED */[java] view plaincopyif (Environment. getExternalStorageState (). equals (Environment. MEDIA_MOU NTED) {String filePath = Environment. getExternalStorageDirectory (). getPath ();} 2. You have obtained the SD card permission./* fileName = Environment. getExternalStorageDirectory () + "/client" is a folder directory */[java] view plaincopyFile f = new File (fileName); // readable if (f. canRead () Log. v ("EagleTag", "very bad"); // writable if (f. canWrite () Log. v ("EagleTag", "very good ");--------------------------------------------------------------------------------- --------------------------- Explanation of android data and system and cache system directory/system stores rom information;/system/app stores the software attached to rom, that is, system software; /system/data stores the data file information of the core system software in/system/app. /Data stores the user's software information (non-built-in rom-installed software);/data/app stores the software installed by the user; /data stores some lib and xml files of all software (including software installed in/system/app and/data/app and/mnt/asec; /data/dalvik-cache stores the cached files of the program. All files here can be deleted. Is/sdcard the same as/mnt/sdcard? What is/mnt/asce used? Let's talk about the/mnt/asce directory. 1. Upgrade android to 2.2 or above. What does this directory do? 2. More than 2.2, new features are available. Where can I install the SD card that can be installed for an application? I searched the entire card and found that all these applications were installed in the. android asecure directory. I only needed to put the cards on the card reader. 3. How does that relate to the system? Anyone who has learned unix knows that mnt is in a directory under/, and the SD card is mounted through mount./mnt is called a mount point, the system can access the SD card through the mount point/mnt 4. There are three directories under/mnt: in asec, secure, and sdcard, asec is the application we installed on the card, and secure is used to encrypt the installation path of the SD card application. I guess that sdcard is the other content on the card. The actual physical directory corresponding to/mnt/asce is/mnt/sdcard /. android_secure (remember that there is a point before android_secure, This is a hidden directory) we can look back at/sdcard and/mnt/sdcard, it is easy to understand:/sdcard directory, this is a soft link (equivalent to a shortcut to a windows Folder). It is linked to the/mnt/sdcard directory, that is, the content of this directory is the content of sdcard. Therefore, after a user program is installed on the SD card, its content may be scattered to:/mnt/asec,/mnt/secure,/data. To implement app2sd, two popular solutions are available: app2ext and data2ext. The two solutions are described below. The principle of app2ext is to delete the app folder in the data area, create an app file in the ext partition of the SD card, and map it to the data area through soft links. In this way, the system will think that the soft link of the app is a real folder and will install all the programs in it, but in fact, these programs are installed on the card. But because the operating system does not know, in this case, we still see that the system shows that this program is installed in the "built-in space. Data2ext is more thorough. Instead of using soft links, it uses the "Mount" function directly, all storage devices in Linux must be mounted into a folder to perform file operations (for example, the SD card is mounted under the/mnt/sdcard directory ). The data folder is originally a partition corresponding to the Flash in the mobile phone. (To keep the terminology accurate, we need to distinguish the Internal Flash from the memory. The Internal Flash is ROM and the memory is RAM ). Data2ext modifies the Mount correspondence, so that the data folder is not mounted with built-in Flash, but the entire ext partition of the SD card. In this way, not only the app, but the data and cache dalvik-cache set by the storage program will be stored in the SD card. As you can see, the location of the dalvik-cache and data folders is a major difference between the two methods. Among them, dalvik-cache is the pre-compiled cache of virtual machines, and data (different from/data, which is/data) is the place where the stored program data, such as the archival records of games, software configuration information. The difference is that if you refresh ROM and app2ext, all programs can be retained, but the configuration information of these programs and the game archive will be lost. Data2ext can be retained together with configuration and archive, but dalvik-cache is also a place that is easy to accumulate garbage, and the garbage will be retained together. Since data2ext places the entire data partition on the SD card, when we need WIPE for ROM flushing, the content of this data Partition may not be affected by wipe, this saves users' personal data, but may also cause inexplicable system faults.

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.