Created
February 1, 2017 18:45
-
-
Save karbunkul/89edb98050ca3661291be0f6f36cfe8c to your computer and use it in GitHub Desktop.
Android permission helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Intent appDetailsIntent(Context context) { | |
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", context.getPackageName(), null)); | |
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
return intent; | |
} | |
private boolean checkCallingOrSelfPermissions(@NonNull Context context, @NonNull String... permissions) { | |
for (String permission : permissions) { | |
if (context.checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_DENIED) { | |
return false; | |
} | |
} | |
return true; | |
} | |
private void requestPermissions(@NonNull Context context, @NonNull String... permissions) { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | |
int REQUEST_PERMISSIONS = PackageManager.PERMISSION_DENIED; | |
for (String permission : permissions) { | |
if (ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) { | |
REQUEST_PERMISSIONS = PackageManager.PERMISSION_GRANTED; | |
break; | |
} | |
} | |
requestPermissions(permissions, REQUEST_PERMISSIONS); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment