android - How to ask for permissions in MiUi pre - Marshmallow? -
int permissioncheck = contextcompat.checkselfpermission(mactivity, manifest.permission.receive_sms); activitycompat.requestpermissions(this, new string[]{manifest.permission.read_contacts}, permission_request_code); log.d(tag, permissioncheck + "");
the permission check returns permission_granted in os (miui) app doesn't have permissions.
test device : redmi note 3 pro (miui 8)
for permissions i'm using such approach:
private boolean permissionsactivated = (build.version.sdk_int < build.version_codes.m); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //.... requirepermissionsifneeded(); //.... } @suppresslint("newapi") private void requirepermissionsifneeded() { // todo auto-generated method stub if (build.version.sdk_int >= build.version_codes.m) { if (!canall()) { permissionsactivated = false; requestpermissions(initial_perms, requestperm); } else { permissionsactivated = true; } } else { permissionsactivated = true; } } @suppresslint("newapi") private boolean haspermission(string perm) { if (build.version.sdk_int >= build.version_codes.m) { return (packagemanager.permission_granted == checkselfpermission(perm)); } else { return true; } } private boolean canall() { // todo auto-generated method stub return (canaccesslocation() && cancoarselocation() && cangetaccounts()); } private boolean canaccesslocation() { return haspermission(android.manifest.permission.access_fine_location); } private boolean cancoarselocation() { return haspermission(android.manifest.permission.access_coarse_location); } private boolean cangetaccounts() { return haspermission(android.manifest.permission.get_accounts); } @override public void onrequestpermissionsresult(int requestcode, string[] permissions, int[] grantresults) { // todo auto-generated method stub super.onrequestpermissionsresult(requestcode, permissions, grantresults); switch (requestcode) { case requestperm: { // if request cancelled, result arrays empty. if (grantresults.length > 0 && grantresults[0] == packagemanager.permission_granted) { permissionsactivated = true; } else { // permission denied, boo! disable // functionality depends on permission. toast.maketext(this, ":(", toast.length_long).show(); permissionsactivated = false; } return; } // other 'case' lines check other // permissions app might request } }
somewhere in code
permissionsactivated = canall();
Comments
Post a Comment