先调用:

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调用系统自带的文件管理器进行文件选择并读取的更多相关文章

  1. (转)Android调用系统自带的文件管理器进行文件选择并获得路径

    Android区别于iOS的沙盒模式,可以通过文件浏览器浏览本地的存储器.Android API也提供了相应的接口. 基本思路,先通过Android API调用系统自带的文件浏览器选取文件获得URI, ...

  2. Android调用系统自带的文件管理器进行文件选择

    http://blog.csdn.net/zqchn/article/details/8770913的补充 FileUtils文件 public class FileUtils {     publi ...

  3. Android调用系统自带的设置界面

    Android有很多系统自带的设置界面,如设置声音,设置网络等. 在开发中可以调用这些系统自带的设置界面. 点击以下列表中的选项,就可以调出相应的系统自带的设置界面. 如点击“无线和网络设置”,可以调 ...

  4. android调用系统自带的的浏览器搜索关键字

    //调用系统的浏览器搜索详情 public void jumpBrowser(String value) { /* 取得网页搜寻的intent */ Intent search = new Inten ...

  5. android 调用系统的音乐和视频播放器

    package com.eboy.testsystemaudiovideo; import android.app.Activity;import android.content.Intent;imp ...

  6. ShareIntentUtil【调用系统自带的分享的工具类】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 根据参考资料的文章,整理了调用系统自带分享的工具类(实现了适配7.0FileProvider的功能),需要搭配<Android ...

  7. Android调用系统相机、自己定义相机、处理大图片

    Android调用系统相机和自己定义相机实例 本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,而且因为涉及到要把拍到的照片显示出来,该样例也会涉及到Android载入大图片时候的处 ...

  8. android调用系统的自定义裁剪后得到的图片不清晰,使用MediaStore.EXTRA_OUTPUT获取缓存下的清晰图片

    在使用系统自带的剪切图片工具时,通常只能设置一些比较小的值,像 intent.putExtra("outputX", 320); intent.putExtra("out ...

  9. Android调用系统相机、自定义相机、处理大图片

    Android调用系统相机和自定义相机实例 本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显示出来,该例子也会涉及到Android加载大图片时候的处理 ...

随机推荐

  1. Android启动过程以及各个镜像的关系

    Android启动过程 Android在启动的时候,会由UBOOT传入一个init参数,这个init参数指定了开机的时候第一个运行的程序,默认就是init程序,这个程序在ramdisk.img中.可以 ...

  2. [HIHO1039]字符消除(字符串,枚举,模拟)

    题目链接:http://hihocoder.com/problemset/problem/1039 思路:枚举所有字符更新的位置和ABC三种修改方案,之后再模拟消除规则,一步一步去消除.直到无法消除, ...

  3. leetcode:Rectangle Area

    Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...

  4. leetcode:Lowest Common Ancestor of a Binary Search Tree

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  5. listview android:cacheColorHint,android:listSelector属性作用

      ListView是常用的显示控件,默认背景是和系统窗口一样的透明色,如果给ListView加上背景图片,或者背景颜色时,滚动时listView会黑掉, 原因是,滚动时,列表里面的view重绘时,用 ...

  6. XML文件读取工具类

    /// <summary> /// Author: jiangxiaoqiang /// </summary> public class XmlReader { //===== ...

  7. php扩展编译(以memcached为例)

    1)到 https://pecl.php.net/ 上搜索并下载(wget)你需要的扩展的源码包 2)解压并切换进入扩展包的目录 3)使用phpize工具自动生成 configure 4)config ...

  8. html常用笔记

    <?php //CSS可以对文本格式进行精确的控制 //HTML标记更有利于搜索引擎 //一.标签 <br> <p>//换行后插入一个空行,单字节不换行,双字节自动换行 ...

  9. 【英语】Bingo口语笔记(78) - let系列

  10. POJ 1942 Paths on a Grid

    // n*m 的格子 从左下角走到右上角的种数// 相当于从 n+m 的步数中选 m 步往上走// C(n+m,m) #include <iostream> #include <st ...