From:http://blog.csdn.net/AMinfo/article/details/7875358


广播接收机代码:

[java] view plain copy print ?
  1. publicclassScanSdReceiverextendsBroadcastReceiver
  2. {
  3. @Override
  4. publicvoidonReceive(Contextcontext,Intentintent)
  5. {
  6. Stringaction=intent.getAction();
  7. if(Intent.ACTION_MEDIA_SCANNER_STARTED.equals(action))
  8. {
  9. //开始扫描,把你的代码放这里
  10. }
  11. elseif(Intent.ACTION_MEDIA_SCANNER_FINISHED.equals(action))
  12. {
  13. //扫描结束,把你的代码放这里
  14. }
  15. }
  16. }

注册广播接收机,监听SDcard扫描事件

[java] view plain copy print ?
  1. IntentFilterintentfilter=newIntentFilter(Intent.ACTION_MEDIA_SCANNER_STARTED);
  2. intentfilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
  3. intentfilter.addDataScheme("file");
  4. ScanSdReceiverscanSdReceiver=newScanSdReceiver();
  5. registerReceiver(scanSdReceiver,intentfilter);

扫描SDCard

[java] view plain copy print ?
  1. sendBroadcast(newIntent(Intent.ACTION_MEDIA_MOUNTED,
  2. Uri.parse("file://"+Environment.getExternalStorageDirectory().getAbsolutePath())));

更多相关文章

  1. Android结束进程的方法
  2. Android拒绝来电的实现--ITelephony类的反射(结束电话)
  3. android 结束进程
  4. 博文视点大讲堂35期-It's Android Time:程序员创富有道! 圆满结束

随机推荐

  1. android VoiceRecognition 语音识别并打
  2. How to Install Ubuntu on Android!
  3. android仿qq分组列表效果
  4. android包重复问题
  5. android根据应用方向自动旋转的自定义vie
  6. Android录音及播放功能实现
  7. Android 文件操作工具类
  8. Unity3d 调用Android震动
  9. Android通过Mainfest设置Theme实现布局全
  10. Android 开发艺术探索 源码地址