ANDROID_ camera Camera_ Call system camera return data null

Source: Internet
Author: User

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

Related Article

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.