Android 7.0 Call camera crash solution
Error Tip:
Android.os.fileuriexposedexception:file:///storage/emulated/0/dcim/img_1041503431.jpg exposed beyond app through ClipData.Item.getUri ()
Treatment mode
/** * Open camera */private void showcameraaction () {if (Contextcompat.checkselfpermission getcontext (), manifest.pe Rmission. write_external_storage)!= packagemanager.permission_granted) {requestpermission (Manifest.permission.WRITE_ External_storage, GetString (r.string.mis_permission_rationale_write_storage), Request_storage_write_access_
PERMISSION);
else {Intent Intent = new Intent (mediastore.action_image_capture); if (Intent.resolveactivity (Getactivity (). Getpackagemanager ())!= null) {try {mtmpfile = Fileutils.createtmpfile (g
Etactivity ());
catch (IOException e) {e.printstacktrace (); } if (mtmpfile!= null && mtmpfile.exists ()) {/* Get the current system's Android version number/int currentapiversion = ANDROID.O
S.build.version.sdk_int;
LOG.E ("Currentapiversion", "currentapiversion====>" +currentapiversion);
if (currentapiversion<24) {Intent.putextra (Mediastore.extra_output, Uri.fromfile (mtmpfile)); Startactivityforresult (iNtent, Request_camera);
}else {contentvalues contentvalues = new Contentvalues (1);
Contentvalues.put (MediaStore.Images.Media.DATA, Mtmpfile.getabsolutepath ());
Uri uri = GetContext (). Getcontentresolver (). Insert (mediastore.images.media.external_content_uri,contentvalues);
Intent.putextra (Mediastore.extra_output, URI);
Startactivityforresult (Intent, Request_camera);
} else {Toast.maketext (getactivity (), R.string.mis_error_image_not_exist, Toast.length_short). Show ();
} else {Toast.maketext (getactivity (), R.string.mis_msg_no_camera, Toast.length_short). Show ();
}
}
}
Thank you for reading, I hope to help you, thank you for your support for this site!