Android app get permission to judge

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.