Android gets a way to monitor SD card status

Source: Internet
Author: User
Tags file system

Android gets a way to monitor SD card status

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.

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.