this blog post for the original, reproduced please specify the source!
http://blog.csdn.net/zimo2013/article/details/169162791. Call the System camera
Instantiate a intent and specify actionintent intent = new Intent (mediastore.action_image_capture);//Specify a file object URI corresponding to the picture path = Uri.fromfile (Imageutil.getimagefile ()); Intent.putextra (Mediastore.extra_output, URI);// Start Activitystartactivityforresult (Intent, Request_code_camera);
but the data obtained in Onactivityresult (int requestcode, int resultcode, Intent data) is always null?
2. Cause Analysis
So I looked at the Android system Framework camera Application , Found the question about how the system camera handles the return value data!
if you specify a target uri,data, there is no data, and if you do not specify a URI, data returns a ! Now think about it, this design is still very reasonable!
@Overrideprotected void Onactivityresult (int Requestcode, int resultcode, Intent data) {switch (requestcode) {case request_code_camera:if (ResultCode = RESULT_OK) {if (Data!=null) {//may not have specified Intent.putextra (mediastore.extra_output, URI);//Returns a thumbnail if (Data.hasextra ("data")) {Bitmap thumbnail = Data.getparcelableextra ("Data"), or//bitmap after the operation}}else{//because the target URI is specified, stored in the target Uri,intent.putextra (Mediastore.extra_ OUTPUT, URI);//through the destination URI, find the image//image scaling process//Operation}}}
3.Android System Camera part key source
First handle the no crop case-just return the value. If the//caller Specifies a "save Uri" then write the data to it ' s//stream. Otherwise, pass back a scaled down version of the bitmap//directly in the Extras.if (Msaveuri! = null) {//exists Msaveuri, which specifies the Target Urioutputstream outputstream = null;try {outputstream = Mcontentresolver.openoutputstream (MSaveUri); o Utputstream.write (data); Outputstream.close (); Setresult (RESULT_OK);//return directly to RESULT_OK without specifying Intentfinish ();} catch (IOException ex) {//Ignore exception} finally {util.closesilently (outputstream);}} else {Bitmap Bitmap = createcapturebitmap (data),//returns RESULT_OK, and contains a intent object, where extra Zhongke key is data, Value is a bitmapsetresult (RESULT_OK, New Intent ("Inline-data"). PutExtra ("Data", bitmap)); Finish ();}
ANDROID_ camera Camera_ Call system camera return data null