onRequestPermissionsResult is not called in fragment android -
i taking runtime permission user using below code in fragment .
if (contextcompat.checkselfpermission(getactivity(), manifest.permission.read_external_storage) != packagemanager.permission_granted) { activitycompat.requestpermissions(mactivity, new string[]{manifest.permission.read_external_storage}, storage_permission_code); }
and overriding
@override public void onrequestpermissionsresult(int requestcode, string permissions[], int[] grantresults) { switch (requestcode) { case 21: { // if request cancelled, result arrays empty. if (grantresults.length > 0 && grantresults[0] == packagemanager.permission_granted) { // permission granted, yay! // contacts-related task need do. } else { // permission denied, boo! disable // functionality depends on permission. toast.maketext(getactivity(), "permission denied", toast.length_short).show(); } return; } // other 'case' lines check other // permissions app might request } }
but override method not called
please give me hint have override in fragment
becouse remember futher u must in activity not in fragment. yoou can d tricky in fragment bad way
this in activity. check permissions , save it
private static final int request_code_get_accounts = 101; private static final int request_audio_permission = 102; @targetapi(23) public void checkaudiopermission() { if (build.version.sdk_int < build.version_codes.m) { playerfragment.setupvisualizerfxandui(); return; } if (this.checkselfpermission(manifest.permission.record_audio) != packagemanager .permission_granted) { requestpermissions(new string[]{manifest.permission.record_audio}, request_audio_permission); } else { playerfragment.setupvisualizerfxandui(); } } @targetapi(23) public void checkgmailpermission() { if (isdeviceonline()) { if (build.version.sdk_int < build.version_codes.m) { showgmailrecfragment(true); return; } if (this.checkselfpermission(manifest.permission.get_accounts) != packagemanager .permission_granted) { requestpermissions(new string[]{manifest.permission.get_accounts}, request_code_get_accounts); return; } else { showgmailrecfragment(true); } } else { utils.showtoast(this, getstring(r.string.no_internet)); } } @override public void onrequestpermissionsresult(int requestcode, string[] permissions, int[] grantresults) { switch (requestcode) { case request_code_get_accounts: if (grantresults[0] == packagemanager.permission_granted) { showgmailrecfragment(true); } else { utils.showtoast(this, getstring(r.string.accounts_permision_denied)); } break; case request_audio_permission: if (grantresults[0] == packagemanager.permission_granted) { playerfragment.setupvisualizerfxandui(); } else { utils.showtoast(this, getstring(r.string.audio_permission_denied)); } default: super.onrequestpermissionsresult(requestcode, permissions, grantresults); break; } }
and on fragment when want check permission again or if user denied it. save permissions
private void setupviewvisualizer() { if (!islivetv && !homevideo.isvideotype()) { ((playeractivity) activity).checkaudiopermission(); } else { return; } }
Comments
Post a Comment