this blog post for the original, reproduced please specify the source! http://blog.csdn.net/zimo2013/article/details/169162791. Call the System camera
[Java] view plaincopy
- Instantiate a intent and specify the action
- Intent Intent = new Intent (mediastore.action_image_capture);
- Specifies a file object that corresponds to a picture path
- URI = Uri.fromfile (Imageutil.getimagefile ());
- Intent.putextra (Mediastore.extra_output, URI);
- Start activity
- Startactivityforresult (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 framework camera application and found out about how the system camera handles the return value data problem!
By default, you do not need to specify Intent.putextra (Mediastore.extra_output, URI); The camera has its own default storage path, and the captured photo will return a thumbnail image. If you want to access the original picture, you can get the original picture position via dat extra. That is, if you specify a target uri,data there is no data, and if you do not specify a URI, then data will be returned ! Now think about it, this design is still very reasonable!
[Java]View Plaincopy
- @Override
- protected 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 image
- if (Data.hasextra ("Data")) {
- Bitmap thumbnail = Data.getparcelableextra ("data");
- //Get bitmap after the operation
- }
- }else{
- //Because the target URI is specified, stored in the target Uri,intent.putextra (Mediastore.extra_output, URI);
- //through the target URI, find the picture
- //Zoom processing of the picture
- //Operation
- }
- }
- }
- }
3.Android System Camera Part key source
[Java]View Plaincopy
- 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 destination URI
- OutputStream outputstream = null;
- try {
- OutputStream = Mcontentresolver.openoutputstream (Msaveuri);
- Outputstream.write (data);
- Outputstream.close ();
- Setresult (RESULT_OK); //return directly to RESULT_OK and do not specify intent
- Finish ();
- } catch (IOException ex) {
- //Ignore exception
- } finally {
- util.closesilently (OutputStream);
- }
- } Else {
- Bitmap Bitmap = createcapturebitmap (data);
- //returns RESULT_OK, and contains a intent object, where extra is data,value as a bitmap
- Setresult (RESULT_OK, new Intent ("Inline-data"). PutExtra ("Data", bitmap));
- Finish ();
- }
ANDROID_ camera Camera_ Call system camera return data null