1、在AndroidManifest.xml 加入读取外部存储器权限


2、注册动态监听U盘插入的广播


IntentFilter filter = null;


filter = new IntentFilter();   
filter.addAction(Intent.ACTION_MEDIA_MOUNTED);   //接受外媒挂载过滤器
filter.addAction(Intent.ACTION_MEDIA_REMOVED);   //接受外媒挂载过滤器    
filter.addDataScheme("file"); 
registerReceiver(mSdcardReceiver, filter,"android.permission.READ_EXTERNAL_STORAGE",null);


BroadcastReceiver mSdcardReceiver = new BroadcastReceiver(){


@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED)){     
     
  Toast.makeText(context, "path:"+intent.getData().getPath(), Toast.LENGTH_SHORT).show();
         
}else if(intent.getAction().equals(Intent.ACTION_MEDIA_REMOVED)){
Log.i("123", "remove ACTION_MEDIA_REMOVED");
}
}

};

更多相关文章

  1. Cocos2d-x + Android(安卓)+ Eclipse + Windows 8
  2. Android如何接收locale改变的消息 || locale改变后,发送什么消息
  3. 【android】Android(安卓)7.0适配步骤
  4. Android判断定位功能是否可用
  5. Android(安卓)检测是否有ROOT权限
  6. Linux Mint下Kindle Fire调试android程序
  7. Android权限控制EasyPermissions
  8. android 打开GPS的几种方式
  9. Android调试工具之Logcat

随机推荐

  1. 安卓巴士Android开发神贴整理
  2. Android(安卓)异步加载深入解析
  3. Android(安卓)下拉刷新控件SwipeRefreshL
  4. Android开发环境
  5. android视频播放器
  6. 关于手机启动的方向,和屏幕的单,双击事件
  7. Android中的 animation
  8. [Android]Android的常用adb命令
  9. Android(安卓)WebView加载H5音视频自动播
  10. Android中imageView图片放大缩小及旋转功