Android SD card Mount judgment

Source: Internet
Author: User

Android differentiate SD does the card have a method that is now mounted? This article describes an android -differentiated SD card that is not currently mounted by the method that touches the Android listening method Broadcastreceiver The use of Tips , with a certain reference to learning value , the needs of friends can see the next

This article is an example of how Android differentiates an SD card from being mounted. Now with the same wheat Academy's Android development teacher to see:

Supply a listening method broadcastreceiver set Intentfilter to:

intent.action_media_mounted
Intent.action_media_eject
Intent.action_media_removed

Then the public void OnReceive (Contextcontext, Intent Intent) ends your starting logic startactivity

Privatefinalbroadcastreceiver Broadcastrec =newbroadcastreceiver ()

{

@Override

publicvoidonreceive (context context, Intent Intent) {

if (intent.getaction (). Equals ("Android.intent.action.MEDIA_MOUNTED"))

//SD The card is now mounted successfully

{

ImagePath =

android.os.Environment.getExternalStorageDirectory ();// of your SD Card Path

}else

if (Intent.getaction (). Equals ("Android.intent.action.MEDIA_REMOVED")

// various non-mounted conditions

|| Intent.getaction (). Equals ("Android.intent.action.ACTION_MEDIA_UNMOUNTED")

|| Intent.getaction (). Equals ("Android.intent.action.ACTION_MEDIA_BAD_REMOVAL"))

{

ImagePath = Android.os.Environment.getDataDirectory ();// your local path

}

}

};

// Select the action you want to monitor in the intentfilter

intentfilter intentfilter =newintentfilter (intent.action_media_mounted);

intentfilter.addaction (intent.action_media_unmounted);

intentfilter.addaction (intent.action_media_removed);

//intentfilter.addaction (intent.action_media_shared);

intentfilter.addaction (intent.action_media_bad_removal);

//intentfilter.addaction (intent.action_media_scanner_started);

//intentfilter.addaction (intent.action_media_scanner_finished);

intentfilter.adddatascheme ("file");

registerreceiver (Broadcastrec, intentfilter);// Register listener function

unregisterreceiver (BROADCASTREC);// Use the Logout broadcast listener function

Hopefully this article will help with our Android programming.

Android SD card Mount judgment

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.