This article illustrates the way Android reads images in SD cards. Share to everyone for your reference, specific as follows:
First, get access to read SD card
<!--Create and delete file permissions in SDcard-->
<uses-permission android:name= "android.permission.MOUNT_UNMOUNT_ Filesystems "/>
<!--write data permissions to SDcard-->
<uses-permission android:name=" Android.permission.WRITE _external_storage "/>
<!--read Data permissions from SDcard-->
<uses-permission android:name=" Android.permission.READ_EXTERNAL_STORAGE "/>
Second, find the directory of SD card
/**
* Environment.getexternalstoragedirectory () obtained: ", Mnt/sdcard" that is, found the root directory of SD card *
* *
private String path= Environment.getexternalstoragedirectory () + "client/tile/1.jpg";
Three, according to the path to get pictures
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 images in SD cards
1, get the path is successful
/**
* Environment.getexternalstoragestate () gets whether the path succeeds/
if (environment.getexternalstoragestate). Equals (environment.media_mounted)) {
String path=environment.getexternalstoragedirectory (). GetPath ();
}
2. Access to SD card 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");
}
For more information on Android-related content readers can view the site: "Android programming development of the SD card operation method Summary", "Android Development introduction and Advanced Course", "Android Resource Operation skills Summary", "Android View tips Summary" and "The Android Control usage Summary"
I hope this article will help you with your Android programming.