(Android Studio Speech Recognizer) I'm getting error 9 (insufficient Privileges) even though I have given it RECORD_AUDIO and INTERNET

老子叫甜甜 提交于 2019-12-05 08:54:25

In case anyone comes to this question and none of the other answers help, you might want to try requesting permissions using the following code:

private void requestRecordAudioPermission() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        String requiredPermission = Manifest.permission.RECORD_AUDIO;

        // If the user previously denied this permission then show a message explaining why
        // this permission is needed
        if (checkCallingOrSelfPermission(requiredPermission) == PackageManager.PERMISSION_DENIED) {
            requestPermissions(new String[]{requiredPermission}, 101);
        }
    }
}

It was just a problem with it not being supported on emulators. It works on a physical device.

What I found is that if you are "just a physical device" and you still get the same error, that is most probably is because if the target SDK in the gradle file. you see in later versions they have changed the level of permission to dangers, so by downgrading it, then you it will work.

"I am not an expert in this, but this worked from me fine"

try these links for references to your project also check all android manifest permissions here and here is a sample project

hope these hints help to solve your problem!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!