接收SDcard插拔广播的 Intent为隐式意图。隐式意图必须要求 IntentFilter中的各项参数匹配

 

   
   
   
   
  1. mReceiver = new BroadcastReceiver() {    
  2.     @Override    
  3.     public void onReceive(Context context, Intent intent) {    
  4.         Log.i("Loger"," Receive SDCard Mount or UnMount!");    
  5.     }    
  6. };    
  7.  
  8. IntentFilter filter = new IntentFilter();    
  9. filter.addAction(Intent.ACTION_MEDIA_MOUNTED);    
  10. filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);    
  11.  
  12. filter.addDataScheme("file");    
  13.  
  14. registerReceiver(mReceiver, filter);