First, create a new class, inherit from Broadcastreceiver, and then go to configure manifest.xml that's needless to say,
Note Some details when configuring manifest.xml
Must be added <data android:scheme= "file"/>
1 <receiverAndroid:name=". Sdreceicer ">2 <Intent-filter>3 <ActionAndroid:name= "Android.intent.action.MEDIA_MOUNTED"/>4 <ActionAndroid:name= "Android.intent.action.MEDIA_UNMOUNTED"/>5 <DataAndroid:scheme= "File"/>6 </Intent-filter>7 </receiver>
And then just a couple of simple judgments.
1 Public classSdreceicerextendsBroadcastreceiver {2 @Override3 Public voidOnReceive (Context context, Intent Intent) {4String action = Intent.getaction ();//which action is being executed5 if("Android.intent.action.MEDIA_MOUNTED". Equals (action)) {6Toast.maketext (Context, "SD card Loaded", Toast.length_short). Show ();7}Else if("Android.intent.action.MEDIA_UNMOUNTED". Equals (action)) {8Toast.maketext (Context, "SD card was uninstalled", Toast.length_short). Show ();9 }Ten } One}
Broadcastreceiver Mount Monitor for SD