Android Call System camera

Source: Internet
Author: User

Call the camera to take a picture of the request code
public static final int request_take_photo_code = 1;
public static final int request_take_photo_code2 = 2;
ImageView to show pictures after taking pictures


private void StartTakePhoto2 () {
Booting the system camera
Intent Intent = new Intent (mediastore.action_image_capture);
Start activity and get return data
Startactivityforresult (Intent, REQUEST_TAKE_PHOTO_CODE2);
}
/**
* Jump to System camera to take pictures
*/
private void Starttakephoto () {
Booting the system camera
Intent Intent = new Intent (mediastore.action_image_capture);
Set up a picture saved after a photo is stored in a file
Intent.putextra (Mediastore.extra_output, Uri.fromfile (ImageFile));
Start activity and get return data
Startactivityforresult (Intent, Request_take_photo_code);
}

/**
* Determine if there is an SD card
*
* @return have SD card return true, otherwise false
*/
Private Boolean Hassdcard () {
Get the state of an external store
String state = Environment.getexternalstoragestate ();
if (Environment.MEDIA_MOUNTED.equals (state)) {
have SD card
return true;
}
return false;
}
/**
* Initialize files that store pictures
*
* @return Initialization successfully returns TRUE, otherwise false
*/
Private Boolean initimagefile () {
Initializing files when there is an SD card
if (Hassdcard ()) {
Constructs the path to the file where the picture is stored, the file name is the current time
String FilePath = Environment.getexternalstoragedirectory ()
. GetAbsolutePath ()
+ "/"
+ System.currenttimemillis ()
+ ". png";
ImageFile = new File (FilePath);
if (!imagefile.exists ()) {//If the file does not exist, create the file
try {
Imagefile.createnewfile ();
} catch (IOException e) {
E.printstacktrace ();
}
}
return true;
}
return false;
}

Android Call System camera

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.