Use the camera with android -
i'm trying use camera app when push button application crashes , in android monitor appears following message:
java.lang.securityexception: permission denial: starting intent { act=android.media.action.image_capture cmp=com.android.camera2/com.android.camera.captureactivity } processrecord{bd3e6b7 4753:com.demonsystem.trackingticket/u0a94} (pid=4753, uid=10094) revoked permission android.permission.camera
this code in main activity:
btncamara.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { intent = new intent(mediastore.action_image_capture); startactivityforresult(i,0); <-- here shows error ocultar(); } });
and these permissions:
private void checkcamerapermission() { int permissioncheck = contextcompat.checkselfpermission( this, manifest.permission.camera); if (permissioncheck != packagemanager.permission_granted) { log.i("mensaje", "no se tiene permiso para la camara!."); activitycompat.requestpermissions(this, new string[]{manifest.permission.camera}, 225); } else { log.i("mensaje", "tienes permiso para usar la camara."); } }
these uses wrote in manifest:
<uses-permission android:name="android.permission.camera" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" />
btncamara.setonclicklistener(new view.onclicklistener() { @override public void onclick (view view){ if (haspermissionusecamera()) { intent = new intent(mediastore.action_image_capture); startactivityforresult(i, 0); ocultar(); } } } public boolean haspermissionusecamera() { if (build.version.sdk_int >= 23) { if (activitycompat.checkselfpermission(getcontext(), manifest.permission.write_external_storage) == packagemanager.permission_granted) { return true; } else { requestpermissions(new string[]{manifest.permission.camera}, 0); return false; } } else { //permission automatically granted on sdk<23 upon installation return true; } } @requiresapi(api = build.version_codes.m) @override public void onrequestpermissionsresult(int requestcode, @nonnull string[] permissions, @nonnull int[] grantresults) { switch (requestcode) { case 0: { if (getactivity().checkselfpermission(manifest.permission.camera) == packagemanager.permission_granted) { intent = new intent(mediastore.action_image_capture); startactivityforresult(i, 0); ocultar(); } else { toast.maketext(getactivity(), "access denied", toast.length_short).show(); } break; } } }
Comments
Post a Comment