5
I created an app webRTC that allows me to do streaming audio and video via using javascript, now I need that by my Android I can access through an app I’m developing.
I’m wearing a Webview to load the URL into the application, but it seems that the Webview is blocking access to Camera and Microphone mobile. I have tried several ways to solve this problem, but nothing has solved this.
Observing: The streamming works correctly in the browser of Android, but a message asks for permission to access the camera and microphone.
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>
Code in C#
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 using the Permissionrequest class, but it is generating the following error:
My attempt was the following:
WebChromeClient mWebChrome = new WebChromeClient();
PermissionRequest request;
mWebChrome.OnPermissionRequest(request.Grant(request.GetResources()));
webV.SetWebChromeClient(mWebChrome);
button.Click += delegate
{
webV.StopLoading();
webV.LoadUrl(txturl.Text);
};
I finally got a little bit of the OnPermissionRequest
, but when I start the APP shows the following error:
Here’s my current code:
string URL = "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!
I haven’t seen the tags, Sorry. I’ll see if I can find something to complement the answer.
– Randrade