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