This is the permission that is applied to the android6.0 version above, to determine whether you have this permission and how to obtain permissions:
Determine if you have permissions
@Override
public void Onrequestpermissionsresult (int requestcode,
string[] Permissions,
Int[] grantresults) {
If the request code is the same as the definition, the per_req_code here is a number that is defined by itself and can be defined arbitrarily.
if (Requestcode==per_req_code) {
if (grantresults!=null&&grantresults.length>0) {
if (grantresults[0]==packagemanager.permission_granted) {
Readinfor ();
}else {
Toast.maketext (Contantsactivity.this, "No Permissions", Toast.length_short). Show ();
}
}
}
}
Action to request permission:
if (build.version.sdk_int>=build.version_codes. M) {
Determine if there is permission
int flag = Activitycompat.checkselfpermission (
Contantsactivity.this,
Android. Manifest.permission.READ_CONTACTS);
if (flag!= packagemanager.permission_granted) {//No permissions
Request permission
Activitycompat.requestpermissions (
contantsactivity.this,//context
New String[]{android. manifest.permission.read_contacts},//What permissions are requested
per_req_code//Request Code
);
}else {
Perform an action with permission
}
}else {
Perform an action with permission
}
}
Android app get permission to judge