Android 6.0 Permission Request

Source: Internet
Author: User

Be sure to add this permission in the manifest configuration file before requesting permission

private static final int my_permissions_request_record_audio = 1; Arbitrarily defined

public void SetPermission () {
if (Contextcompat.checkselfpermission (this,
Manifest.permission.RECORD_AUDIO) //The recording permission is applied here
! = packagemanager.permission_granted) {
To apply when you don't have permission.
Activitycompat.requestpermissions (This,
New String[]{manifest.permission.record_audio},
My_permissions_request_record_audio);
}else{
Perform tasks normally
}
}


Permission Request Results
@Override
public void Onrequestpermissionsresult (int requestcode, @NonNull string[] permissions, @NonNull int[] grantresults) {
Switch (requestcode) {
Case My_permissions_request_record_audio:
if (grantresults.length > 0 && grantresults[0] ==packagemanager.permission_granted) {
Permission Request succeeded
} else {
Application failure
Toastutils.show (This, "Please open in Authorization Management");
}
Break
Default
Break

}
}

Android 6.0 Permission Request

Related Article

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.