监听SDCard安装和卸载的Android代码
2018-07-20 来源:open-open
// 监听类 private final BroadcastReceiver sdcardListener = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Log.d("TAG", "sdcard action:::::" + action); if(Intent.ACTION_MEDIA_MOUNTED.equals(action) || Intent.ACTION_MEDIA_SCANNER_STARTED.equals(action) || Intent.ACTION_MEDIA_SCANNER_FINISHED.equals(action) ){ // SD卡成功挂载 } else if(Intent.ACTION_MEDIA_REMOVED.equals(action) || Intent.ACTION_MEDIA_UNMOUNTED.equals(action) || Intent.ACTION_MEDIA_BAD_REMOVAL.equals(action) ){ // SD卡挂载失败 } } }; // 注册监听 private void registerSDCardListener(){ IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED); intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED); intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED); intentFilter.addAction(Intent.ACTION_MEDIA_REMOVED); intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); intentFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL); intentFilter.addDataScheme("file"); registerReceiver(sdcardListener, intentFilter); }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
下一篇:Android中缩放图片
最新资讯
热门推荐