http://www.cnblogs.com/hyzhou/p/3635676.html
一、获取读取SD卡的权限
<!--在SDCard中创建与删除文件权限 --> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <!-- 往SDCard写入数据权限 --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <!-- 从SDCard读取数据权限 --> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
二、找到SD卡的目录
/** * Environment.getExternalStorageDirectory()得到:“、mnt/sdcard” 即找到了sd卡的根目录 */ private String path=Environment.getExternalStorageDirectory()+"client/tile/1.jpg";
三、根据路径获取图片
File mFile=new File(path); //若该文件存在 if (mFile.exists()) { Bitmap bitmap=BitmapFactory.decodeFile(path); return bitmap; }
注意:
在读取sd卡中图片的过程中的一些可用判断
1、
/** * Environment.getExternalStorageState()获取路径是否成功 */ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { String path=Environment.getExternalStorageDirectory().getPath(); }
2、获取SD卡权限成功
private String path=Environment.getExternalStorageDirectory()+"client"; File file=new File(path); if (file.canRead()) { Log.v("TAG", "可读"); } if (file.canWrite()) { Log.v("TAG", "可写"); }