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 |