You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
using Android.Annotation;
|
|
using Android.App;
|
|
using Android.Content;
|
|
using Android.Webkit;
|
|
using Demo.Droid.Controls;
|
|
using Xamarin.Forms;
|
|
using Xamarin.Forms.Platform.Android;
|
|
|
|
[assembly: ExportRenderer(typeof(Xamarin.Forms.WebView), typeof(MyWebViewRenderer))]
|
|
|
|
namespace Demo.Droid.Controls
|
|
{
|
|
public class MyWebViewRenderer : WebViewRenderer
|
|
{
|
|
private Activity mContext;
|
|
|
|
public MyWebViewRenderer(Context context) : base(context)
|
|
{
|
|
this.mContext = context as Activity;
|
|
}
|
|
|
|
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
|
|
{
|
|
base.OnElementChanged(e);
|
|
Control.SetWebChromeClient(new MyWebClient(mContext));
|
|
}
|
|
|
|
private class MyWebClient : WebChromeClient
|
|
{
|
|
private Activity mContext;
|
|
|
|
public MyWebClient(Activity context)
|
|
{
|
|
this.mContext = context;
|
|
}
|
|
|
|
[TargetApi(Value = 21)]
|
|
public override void OnPermissionRequest(PermissionRequest request)
|
|
{
|
|
mContext.RunOnUiThread(() =>
|
|
{
|
|
request.Grant(request.GetResources());
|
|
});
|
|
}
|
|
}
|
|
}
|
|
} |