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