Android WebView onPermissionRequest is not calling

86
April 19, 2022, at 10:20 PM

I m new to Pyjnius and android. I m trying to make a video calling app But my onPermissionRequest is not Called when my WebView PopUps...

In My logcat onPermissionRequest should Print "onPermissionRequest: " but its not..

My Code:

Main.py-

import os
path = os.getcwd()

from jnius import autoclass, JavaClass, MetaJavaClass

from kivy.uix.widget import Widget
from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivymd.uix.button import MDFlatButton
from kivymd.uix.screen import MDScreen
from android.runnable import run_on_ui_thread as run_thread
from android.permissions import request_permissions, Permission


request_permissions([Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE, Permission.CAMERA,Permission.RECORD_AUDIO,Permission.MODIFY_AUDIO_SETTINGS])


WebView = autoclass('org.kivy.MyWebView')



                                
@run_thread
def Open_WebView(link, *args):  
    activity = autoclass('org.kivy.android.PythonActivity').mActivity
             
    webview = WebView(activity)
    settings = webview.getSettings()
    settings.setJavaScriptEnabled(True)
    settings.setUseWideViewPort(True) # enables viewport html meta tags
    settings.setLoadWithOverviewMode(True) # uses viewport
    settings.setSupportZoom(True) # enables zoom
    settings.setUseWideViewPort(True)
    settings.setMediaPlaybackRequiresUserGesture(False)
    
    activity.setContentView(webview)
    webview.loadUrl(link)

Builder.load_string("""
<MyWebView>
    size: 200, 200
    MDFlatButton:
        text: "Push"
        pos_hint: {"center_x": .5, "center_y": .4}
        on_press: root.Push()
""")

class MyWebView(Widget):
    def Push(self):
        Open_WebView(f"file://{path}/index.html?appid=0b4eb79510b4xxxxxxx9b0898&channel=prem&token=")


class MyWebApp(MDApp):
    def build(self):
        return MyWebView()


if __name__ == '__main__':
    MyWebApp().run()

MyWebView.java

package org.kivy;

import android.util.Log;
import android.webkit.ConsoleMessage;
import android.webkit.WebChromeClient;
import android.webkit.PermissionRequest;
import android.webkit.WebView;
import android.content.Context;
import android.util.AttributeSet;

public class ChromeClient extends WebView {
        public ChromeClient(Context context) {
            super(context);
            initView(context);
        }
        public ChromeClient(Context context, AttributeSet attrs) {
            super(context, attrs);
            initView(context);
        }
        private void initView(Context context){
             // i am not sure with these inflater lines
             // you should not use a new instance of MyWebView here             
             // MyWebView view = (MyWebView) inflater.inflate(R.layout.custom_webview, this);
             this.getSettings().setJavaScriptEnabled(true) ;
             this.getSettings().setUseWideViewPort(true);
             this.getSettings().setLoadWithOverviewMode(true);
             this.getSettings().setDomStorageEnabled(true);
             
             this.setWebChromeClient(new WebChromeClient() {
            @Override
            public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            Log.d("My App Log: ", consoleMessage.message());
            return true;
            
    }
             @Override
            public void onPermissionRequest(final PermissionRequest request) {
                Log.d("My Request", "onPermissionRequest: " + String.valueOf(request.getResources()));
                request.grant(request.getResources());
}
  });
};
        }

My onConsoleMessage is Working Totaly Fine but onPermissionRequest is not Working. Please help...

Rent Charter Buses Company
READ ALSO
RN Release build fails, but debug runs. Error:Execution failed for task &#39;:app:compileReleaseJavaWithJavac&#39;

RN Release build fails, but debug runs. Error:Execution failed for task ':app:compileReleaseJavaWithJavac'

I have a react-native app that runs perfectly well in debug, but fails on a release buildRunning node 16

80
Firebase Push notification not receiving on Android 12

Firebase Push notification not receiving on Android 12

My XamarinAndroid app's push notification only works on Android 11 (Pixel 3 XL)

94
How to print an image with bulktransfer() in Android

How to print an image with bulktransfer() in Android

I'm new to Androidi need to print an image via USB

57
How can I create a wrapper for the RecyclerView Adapter that will accept any Adapter that implements RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt;

How can I create a wrapper for the RecyclerView Adapter that will accept any Adapter that implements RecyclerView.Adapter<RecyclerView.ViewHolder>

I know the title is a bit weird, sorryThis is a weird one that I'm not even sure I can explain it correctly, here is my attempt:

126