Android programming to read images in SD card _android

Source: Internet
Author: User
Tags file permissions

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.