Android call system camera three steps away

Source: Internet
Author: User

The first step:

<uses-permissionandroid:name=" Android.permission.WRITE_EXTERNAL_STORAGE "/>

< uses-permission android:name="Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/ >


Step Two:


Intent Intent = new Intent (Mediastore. Action_image_capture);

Startactivityforresult (Intent, 1);


Step Three:

protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
TODO auto-generated Method Stub
Super.onactivityresult (Requestcode, ResultCode, data);
if (ResultCode = = NEWSACTIVITY.RESULT_OK) {
String sdstatus = Environment.getexternalstoragestate ();
if (!sdstatus.equals (environment.media_mounted)) {//Detect if SD is available
LOG.I ("Testfile",
"SD card isn't avaiable/writeable right now.");
Return
}
String name = new DateFormat (). Format ("Yyyymmdd_hhmmss", Calendar.getinstance (Locale.china)) + ". jpg";
Toast.maketext (this, name, Toast.length_long). Show ();
Bundle bundle = Data.getextras ();
Bitmap Bitmap = (Bitmap) bundle.get ("Data");//Get the data returned by the camera and convert it to Bitmap picture format

FileOutputStream B = null;
//??????????????????????????????? Why not directly saved in the System album location???????????????????
File File = new file ("/sdcard/myimage/");
File.mkdirs ();//Create Folder
String fileName = "/sdcard/myimage/" +name;

try {
b = new FileOutputStream (fileName);
Bitmap.compress (Bitmap.CompressFormat.JPEG, +, b);//write data to file
} catch (FileNotFoundException e) {
E.printstacktrace ();
} finally {
try {
B.flush ();
B.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
ImageView iv= (ImageView) Findviewbyid (r.id.news_imageview_image);
Iv.setimagebitmap (bitmap);
}
}


Android call system camera three steps away

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.