The example in this article describes how Android gets to listen for SD card status. Share to everyone for your reference. The specific analysis is as follows:
1. Register Storageeventlistener to monitor the SD card state that is the onstoragestatechanged () method, when the SD card state changes, call this method.
Copy Code code as follows:
public void onstoragestatechanged (String path,string oldstate,string newstate) {
if (Newstate.equals (environment.media_shared))//Bulk Storage
{
/////////////////
else if (newstate.equals (environment.media_removed))//SD card removed
{
////////////////////
}
}
The judgment of each state is generally used in the Environment class:
Media_bad_removal: Indicates that SDcard was removed before being unloaded
Media_checking: Indicates that the object is checking on disk
Media_mounted: Indicates that the SD object is present and has read/write permissions
Media_mounted_read_only: Indicates that object permissions are read-only
Media_nofs: Indicates that the object is blank or is using an unsupported file system
Media_removed: If there is no sdcard return
Media_shared: If SDcard is not installed and is returned via USB bulk storage share
Media_unmountable: Return SDcard cannot be installed if SDcard is present but cannot be installed
Media_unmounted: Return SDcard has been unloaded if sdcard is present but not installed
2. Environment.getexternalstoragestate () directly obtain the status information of the current SD card.
I hope this article will help you with your Android program.