I. Get permission to read the SD card
<!--Create and delete files in SDcard permissions--
<uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<!--write data to sdcard permissions--
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
<!--read data from SDcard permissions--
<uses-permission android:name= "Android.permission.READ_EXTERNAL_STORAGE"/>
Second, find the SD card directory
/** * Environment.getexternalstoragedirectory () obtained: ", Mnt/sdcard" that found the root directory of the SD card */ private String path= Environment.getexternalstoragedirectory () + "client/tile/1.jpg";
Third, get the picture according to the path
File Mfile=new file (path); If the file exists if (mfile.exists ()) { Bitmap bitmap=bitmapfactory.decodefile (path); return bitmap; }
Attention:
Some of the available judgments in the process of reading an image from an SD card
1.
/**
* Environment.getexternalstoragestate () Gets the path is successful
*/
if (Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {
String path=environment.getexternalstoragedirectory (). GetPath ();
}
2. Get SD card permissions successfully
Private String Path=environment.getexternalstoragedirectory () + "client";
File File=new file (path);
if (File.canread ()) {
LOG.V ("TAG", "readable");
}
if (File.canwrite ()) {
LOG.V ("TAG", "writable");
}
Android to read images from SD card