java - Android Multiple Permissions Error -
i have method should check if permission need have granted or not :
public boolean checkcamera(){ string[] permissions= new string[]{ manifest.permission.write_external_storage, manifest.permission.camera}; int result; list<string> listpermissionsneeded = new arraylist<>(); (string p:permissions) { result = contextcompat.checkselfpermission(getapplicationcontext(),p); if (result != packagemanager.permission_granted) { listpermissionsneeded.add(p); } } if (!listpermissionsneeded.isempty()) { activitycompat.requestpermissions(this, listpermissionsneeded.toarray(new string[listpermissionsneeded.size()]),multiple_permissions ); return false; } return true; }
if not, request these permissions. problem is, if denied 1 of them pass valid permission.
private void requestpermissioncamera(){ if(checkcamera()){ values.put(mediastore.images.media.title, "new picture"); values.put(mediastore.images.media.description, "from camera"); imageuri = getcontentresolver().insert( mediastore.images.media.external_content_uri, values); intent intent = new intent(mediastore.action_image_capture); intent.putextra(mediastore.extra_output, imageuri); startactivityforresult(intent,requestcodecamera); } }
in moment checks, it's not returning false should , on requestresult same thing.
@override public void onrequestpermissionsresult(int requestcode, @nonnull string[] permissions, @nonnull int[] grantresults) { switch (requestcode){ case multiple_permissions: if(grantresults.length > 0 && grantresults[0] == packagemanager.permission_granted){ values.put(mediastore.images.media.title, "new picture"); values.put(mediastore.images.media.description, "from camera"); imageuri = getcontentresolver().insert( mediastore.images.media.external_content_uri, values); intent intent = new intent(mediastore.action_image_capture); intent.putextra(mediastore.extra_output, imageuri); startactivityforresult(intent,requestcodecamera); } else { toast.maketext(this, "not permissions granted", toast.length_short).show(); } break; case read_storage:
Comments
Post a Comment