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