locked
Enable microphone capabilities to enable voice in web view RRS feed

  • Question

  • User396593 posted

    Hello everyone,

    We have a chat bot service/portal which we are going to render it inside web view, we have features like text/voice input for chatting.

    Need help/guidance to enable microphone capabilities to enable voice in web view for both iOS and Android platform.

    Thanks!!

    Tuesday, September 1, 2020 1:49 PM

All replies

  • User369978 posted

    iOS

    Add permission for Microphone in info.plist

    Key:Privacy - Microphone Usage Description  
    Value: Do you allow this App to use your microphone ?
    

    Android

    Add permission in manifest .

    ?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.app18" android:installLocation="auto"> <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" /> <application android:label="App18.Android"></application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> </manifest>

    And set in custom renderer .

    ``` [assembly: ExportRenderer(typeof(WebView), typeof(MyWebViewRenderer))] namespace xxx.Droid { public class MyWebViewRenderer : WebViewRenderer { Activity mContext; public MyWebViewRenderer(Context context) : base(context) { this.mContext = context as Activity; } protected override void OnElementChanged(ElementChangedEventArgs e) { base.OnElementChanged(e); Control.Settings.JavaScriptEnabled = true; Control.ClearCache(true); Control.SetWebChromeClient(new MyWebClient(mContext)); } public class MyWebClient : WebChromeClient { Activity mContext; public MyWebClient(Activity context) { this.mContext = context; } [TargetApi(Value = 21)] public override void OnPermissionRequest(PermissionRequest request) { mContext.RunOnUiThread(() => { request.Grant(request.GetResources());

                        });
    
            }
        }
    
    }
    

    } ```

    Wednesday, September 2, 2020 8:30 AM
  • User396593 posted

    @ColeX Thankyou, I tried implementing this solution to enable voice for web view but when try to open the link inside web view it takes me to Chrome browser.

    Want to handle it within the web view control.

    Any suggestions would be of great help.

    Thanks!!

    Wednesday, September 2, 2020 8:38 AM
  • User369978 posted

    @developer9920 said: @ColeX Thankyou, I tried implementing this solution to enable voice for web view but when try to open the link inside web view it takes me to Chrome browser.

    Want to handle it within the web view control.

    Any suggestions would be of great help.

    Thanks!!

    I'm afraid i's impossible , i try to use WebViewClient instead of WebChromeClient , refer to here , but WebViewClient doesn't contain the method to handle the permissions.

    Thursday, September 3, 2020 8:48 AM