Android6.0 model on call system camera take photos return ResultCode value always equals 0 problem

Source: Internet
Author: User

Tag: greater than or equal to Rect causes ERR ash strong implementation article allows

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Under normal circumstances, call the system camera to take pictures:
If you click on the "OK" icon after taking the photo, the Returned resultcode =-1 (ACTIVITY.RESULT_OK);
If you click on the "Back" button at the bottom, the returned resultcode = 0 (activity.result_canceled).

Simple to invoke the system camera's notation:

// Call system to take pictures New  New Date () + ". jpg"= environment.getexternalstoragedirectory () + File.separator + "tempwhy" + File.separator + photofilename; // You must use a folder that already exists tempwhyIntent.putextra (Mediastore.extra_output, Uri.fromfile (new  File (Imgurl)) ); // start the photo-taking form. and register callback processing Startactivityforresult (intent, 1111);

Processing on return

  @Override  public  void  onactivityresult (int   ResultCode, Intent data) { super  .onactivityresult (Requestcode,    ResultCode, data);  if  (resultcode == ACTIVITY.RESULT_OK) { /span>switch   (Requestcode) { //  camera feature  case  1111:  break  ; }    }}

So, the call system that came up today on the Android6.0 model, the value of the ResultCode returned by the camera is always equal to 0, mainly due to the following two causes:

One, do not implement run-time permissions processing
When the android:targetsdkversion value in the Androidmanifest.xml file is greater than or equal to 23, the run-time permission must be processed, because the permission to read and write to the SD card Android.permission.WRITE_SETTINGS belongs to run-time permissions.
Solution:
Scenario One: Modify the Android:targetsdkversion value in the Androidmanifest.xml file to less than 23
Scenario two: Adding processing of run-time permissions

second, the Storage Directory (folder) is not created when you save the path to the designated picture
Solution:

Create a storage directory before calling the system camera to take a photo

Android6.0 model on call system camera take photos return ResultCode value always equals 0 problem

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.