Allow Camera and Microphone access to a WebView by Xamarin Android

5

I've created a webRTC application that allows me to do streaming audio and video via javascript, now I need it by my Android I can access through an app I'm developing.

I'm using a WebView to load the URL into the app, but it looks like WebView is blocking access to the Camera and Microphone on your phone. I have tried several ways to solve this problem, but nothing solved this.

Comment : Streaming works correctly in the Android browser, however a message appears asking for camera and microphone access permission.

AndroidManifest xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="LexLoco.LexLoco" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="16" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
  <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.CAPTURE_SECURE_VIDEO_OUTPUT" />
    <uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="com.android.voicemail.permission.READ_VOICEMAIL" />
    <uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" />
    <application android:label="LexLoco"></application>
</manifest>

C # code

            Button button = FindViewById<Button>(Resource.Id.MyButton);
            EditText txturl = FindViewById<EditText>(Resource.Id.editText1);
            txturl.Text = URL;

            WebView webV = FindViewById<WebView>(Resource.Id.webViewer);
            WebSettings webSettings = webV.Settings;

            webSettings.JavaScriptEnabled = true;
            webSettings.AllowFileAccessFromFileURLs = true;
            webSettings.AllowUniversalAccessFromFileURLs = true;

            webV.SetWebViewClient(new WebViewClient());

            button.Click += delegate {
                webV.StopLoading();
                webV.LoadUrl(txturl.Text);
            };

I tried to use the PermissionRequest class, however it is generating the following error:

Myattemptwasasfollows:

WebChromeClientmWebChrome=newWebChromeClient();PermissionRequestrequest;mWebChrome.OnPermissionRequest(request.Grant(request.GetResources()));webV.SetWebChromeClient(mWebChrome);button.Click+=delegate{webV.StopLoading();webV.LoadUrl(txturl.Text);};

IfinallygotalittleunderstandingofOnPermissionRequest,butwhenIstartAPPithasthefollowingerror:

Hereismycurrentcode:

stringURL="https://www.onlinemictest.com/";
        PermissionRequest req;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);
            Button button = FindViewById<Button>(Resource.Id.MyButton);
            EditText txturl = FindViewById<EditText>(Resource.Id.editText1);
            txturl.Text = URL;

            WebView webV = FindViewById<WebView>(Resource.Id.webViewer);
            WebSettings webSettings = webV.Settings;

            webSettings.JavaScriptEnabled = true;
            webSettings.AllowFileAccessFromFileURLs = true;
            webSettings.AllowUniversalAccessFromFileURLs = true;

            WebChromeClient mWebChrome = new WebChromeClient();
           try
            {
            mWebChrome.OnPermissionRequest(req);
            }
            catch(System.Exception ex)
            {
                alertShow(ex.Message);
            }

            webV.SetWebChromeClient(mWebChrome);
            button.Click += delegate
            {
                webV.StopLoading();
                webV.LoadUrl(txturl.Text);
            };
        }
        public void OnPermissionRequest(Android.Webkit.PermissionRequest request)
        {
            try
            { 
            req = request;
            request.Grant(request.GetResources());
            }
            catch (System.Exception ex)
            {
                alertShow(ex.Message);
            }
        }
        public void alertShow(string msg)
        {

            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.SetMessage(msg);
            alert.Show();
        }

Please help me, I'm getting ugly here!

    
asked by anonymous 08.11.2016 / 13:48

0 answers