[Android Pro] StorageManager Introduction

Source: Internet
Author: User

StorageManager

StorageManager is the interface to the systems storage service. The storage Manager handles storage-related items such as Opaque Binary Blobs (Obbs).

Obbs contain a filesystem that maybe being encrypted on disk and mounted on-demand from an application. Obbs is a good a-providing large amounts of binary assets without packaging them into APKs as they could be multiple g Igabytes in size. However, due to their size, they ' re most likely stored in a GKFX storage pool accessible from all programs. The system does not guarantee the security of the OBB file itself:if any program modifies the OBB, there is no guarantee That a read from that OBB would produce the expected output.

Get An instance of the This class by calling with an getSystemService(java.lang.String) argument of STORAGE_SERVICE .

A new Obb file system and StorageManager class have been added from Android 2.3 to manage data security on external storage.

If we design a resource that contains more games, you may find that the resulting APK file may be up to 300MB, but the apk file is so large that the Android system does not install properly, and that this is actually a resource file that is used in the game, we may be able to access it on the SD card. , for example, the picture manager of the system will index the picture resources in the game, and the music player will also index the music in the resources, so the Android 2.3 obb file (Opaque Binary Blob) can solve the large file on the SD card to separate the apk file, At the same time, other programs do not have permission to access such an isolated file system.
The instantiation method of the Android.os.storage.StorageManager class requires the use of Getsystemservice (Contxt.storage_service), EoE again to remind this is an API Level at least 9 to invoke the class, note the SDK version and the firmware of the target device.

We know that there are usually external memory cards on Android,
But the environment.getexternalstoragedirectory () gets the built-in memory card location (and some phones can modify the default storage in the system) so how do I get the location of the external memory card?

Getting multiple SDcard with StorageManager is better than using cat/proc/mounts:

 Public Staticstring[] Getstoragepaths (Context cxt) {List<String> pathslist =NewArraylist<string>(); if(Android.os.Build.VERSION.SDK_INT <Android.os.Build.VERSION_CODES. Gingerbread) {StringBuilder sb=NewStringBuilder (); Try{Pathslist.addall (NewSdcardfetcher (). Getstoragepaths (NewFileReader ("/proc/mounts"), SB); } Catch(FileNotFoundException e) {e.printstacktrace (); File Externalfolder=environment.getexternalstoragedirectory (); if(Externalfolder! =NULL) {Pathslist.add (Externalfolder.getabsolutepath ()); }            }        } Else{StorageManager StorageManager=(StorageManager) Cxt.getsystemservice (Context.storage_service); Try{Method Method= StorageManager.class. Getdeclaredmethod ("Getvolumepaths"); Method.setaccessible (true); Object result=Method.invoke (StorageManager); if(Result! =NULL&& resultinstanceofstring[]) {string[] pathes=(string[]) result;                    StatFs StatFs;  for(String path:pathes) {if(! Textutils.isempty (PATH) &&NewFile (path). Exists ()) {StatFs=NewStatFs (path); if(Statfs.getblockcount () * Statfs.getblocksize ()! = 0) {pathslist.add (path); }                        }                    }                }            } Catch(Exception e) {e.printstacktrace (); File Externalfolder=environment.getexternalstoragedirectory (); if(Externalfolder! =NULL) {Pathslist.add (Externalfolder.getabsolutepath ()); }            }        }        returnPathslist.toarray (Newstring[pathslist.size ()]); }

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.