4

I'm converting a flaskapp combined with SpeechRecognition Javascript into an apk (I get the html here) . And i tried to add the Microphone permission by adding:

Python:

from android.permissions import Permission, request_permissions 
request_permissions([Permission.INTERNET,Permission.MODIFY_AUDIO_SETTINGS,Permission.RECORD_AUDIO])

Buildozer.spec

android.permissions = INTERNET,RECORD_AUDIO,MODIFY_AUDIO_SETTINGS
android.api = 30

But when i run apk, i still got not-allowed error in javascript.

Thanks For Any Helps!

Dile
  • 516
  • 3
  • 13

1 Answers1

0

Issue could be because webview used in android might not have permissions handler. Assuming you used setWebViewClient or setWebChromeClient based on documentation doclink

webView.setWebChromeClient(new WebChromeClient() {
    @Override
    public void onPermissionRequest(final PermissionRequest request) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            myRequest = request;
            for (String permission : request.getResources()) {
                if (permission.equals("android.webkit.resource.AUDIO_CAPTURE")) {
                    demandForPermission(request.getOrigin().toString(), Manifest.permission.RECORD_AUDIO, MY_PERMISSIONS_REQUEST_RECORD_AUDIO);
                } else {
                    myRequest.grant(request.getResources());
                }
            }
        }
    }

    @Override
    public void onPermissionRequestCanceled(PermissionRequest request) {
        super.onPermissionRequestCanceled(request);
    }

Try adding and handling permission to correct this issue.

  • I don't have much experiences in java, i just buid apk with p4a and buildozer. Butcan you add more specific information about something like how can i add it or where can i use. Also i found that P4a Webview using webview jni (Maybe it will helps!). But thanks you for your attention – Dile Aug 24 '23 at 15:02
  • Sure, [link](https://python-for-android.readthedocs.io/en/latest/buildoptions/?highlight=webview#webview) try adding permission to webview – VijayAnand Ayyasamy Aug 25 '23 at 05:21
  • Sorry , i am very busied in few days ago . So i couldn't reply, and this documention is for python-for-android. I have readed it , and try to adding some permissions. But they didn't work. But i find something [that](https://github.com/kivy/python-for-android/blob/3107e4e788e152fc3c69e0ff67702d670a23d970/pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java) is the Java code of webview. Maybe i can try to add code into it . But thanks you – Dile Sep 01 '23 at 02:04