Android 6.0 above dynamic access issues, Baidu speech recognition

Source: Internet
Author: User

As the robot board upgrade to the Android 7.0 system, so there is no voice wake, can not recognize the problem, immediately realize that should be more than Android 6.0 need to dynamically get permission to cause, then wrote the dynamic request permission, called the dynamic permission callback. That's good enough. Next paste the code, hope to be helpful to everyone.

/**
* Android 6.0 above requires dynamic request permission
*/
private void Initpermission () {
String permissions[] = {
Manifest.permission.RECORD_AUDIO,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.MODIFY_AUDIO_SETTINGS,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.WAKE_LOCK,
Manifest.permission.RECEIVE_BOOT_COMPLETED
};

arraylist<string> toapplylist = new arraylist<string> ();

for (String perm:permissions) {
if (packagemanager.permission_granted! = Contextcompat.checkselfpermission (this, perm)) {
Toapplylist.add (perm);
Entering here means that there is no permission.
LOG.E ("--------->", "No Permissions");
} else {

LOG.E ("--------->", "authorized");
}
}
String tmplist[] = new string[toapplylist.size ()];
if (!toapplylist.isempty ()) {
Activitycompat.requestpermissions (This, Toapplylist.toarray (tmplist), 123);
}

}

@Override
public void Onrequestpermissionsresult (int requestcode, @NonNull string[] permissions, @NonNull int[] grantresults) {
Super.onrequestpermissionsresult (Requestcode, permissions, grantresults);
Switch (requestcode) {
Case 1: {
Authorization is allowed
if (Grantresults.length > 0
&& Grantresults[0] = = packagemanager.permission_granted) {
LOG.E ("-------->", "Authorization request is allowed");
Permission was granted, yay! Do the
contacts-related task need to do.

} else {
LOG.E ("-------->", "Authorization request denied");
}
Return
}
}
}



The Initpermission method is then called in the OnCreate method to complete.

Android 6.0 above dynamic access issues, Baidu speech recognition

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.