Open ythy opened 5 years ago
验证是否有某个权限
private boolean checkWriteExternalPermission()
{
String permission = android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
int res = getContext().checkCallingOrSelfPermission(permission);
return (res == PackageManager.PERMISSION_GRANTED);
}
Requests permissions to be granted to this application. These permissions must be requested in your manifest.
If your app does not have the requested permissions the user will be presented with UI for accepting them. After the user has accepted or rejected the requested permissions you will receive a callback on
onRequestPermissionsResult(int, String[], int[])
reporting whether the permissions were granted or not.Note that requesting a permission does not guarantee it will be granted and your app should be able to run without having this permission.
You cannot request a permission if your activity sets
noHistory
totrue
because in this case the activity would not receive result callbacks includingonRequestPermissionsResult(int, String[], int[])
.A sample example: