Android调用系统自带的文件管理器进行文件选择并读取
2016-08-09 16:20
579 查看
先调用:
再在 onActivityResult 里做对uri相应的操作(目前只能读操作)
intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); //设置类型,我这里是任意类型,任意后缀的可以这样写。 intent.addCategory(Intent.CATEGORY_OPENABLE); // 只有设置了这个,返回的uri才能使用 getContentResolver().openInputStream(uri) 打开。 startActivityForResult(intent, 1);
再在 onActivityResult 里做对uri相应的操作(目前只能读操作)
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode == Activity.RESULT_OK && data != null) { try { readBytes(data.getData()); } catch (IOException e) { e.printStackTrace(); } } } public byte[] readBytes(Uri inUri) throws IOException { InputStream inputStream = getContentResolver().openInputStream(inUri); // this dynamically extends to take the bytes you read ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); // this is storage overwritten on each iteration with bytes int bufferSize = 1024; byte[] buffer = new byte[bufferSize]; // we need to know how may bytes were read to write them to the byteBuffer int len = 0; while ((len = inputStream.read(buffer)) != -1) { byteBuffer.write(buffer, 0, len); Log.i("welhzh_f", "" + len); } // and then we can return your byte array. return byteBuffer.toByteArray(); }
相关文章推荐
- Android调用系统自带的文件管理器进行文件选择并获得路径,android文件管理器
- Android调用系统自带的文件管理器进行文件选择
- Android调用系统自带的文件管理器进行文件选择
- Android调用系统自带的文件管理器进行文件选择
- Android调用系统自带的文件管理器进行文件选择
- Android调用系统自带的文件管理器进行文件选择并获得路径
- Android调用系统自带的文件管理器进行文件选择
- Android调用系统自带的文件管理器进行文件选择
- Android调用系统自带的文件管理器进行文件选择并获得路径,android文件管理器
- Android调用系统自带的文件管理器进行文件选择并获得路径,android文件管理器
- Android调用系统自带的文件管理器进行文件选择
- android 调用系统自带的选择图片 然后进行自定义大小裁剪
- Android 调用系统相机拍照(适配7.0)、从图库选择图片、从数据库读取联系人信息、相册图片、扫描文件
- android调用系统自带的文件管理程序选择文件
- android开发中调用系统自带的文件选择器遇到的一些问题
- Android调用系统拍照 读取选择的角度
- android调用系统相机拍照与打开相册选择照片进行截取保存笔记
- android中通过JNI读取Bitmap文件,并调用opencv进行处理
- Android编程调用系统自带的拍照功能并返回JPG文件示例【附demo源码下载】
- Android 调用系统相机进行拍照 使用自带的图片选择器和裁剪工具