I have Marked one problem on Playstore and google send the mail my app is unsafe because use of SSL.
Currently in my application I have one webview
which is load link and it contains https url.
on web settings I'm doing like this:
web.setWebViewClient(new SSLTolerentWebViewClient());
to ignore ssl certificate I use following code but because of ignoring certificate playstore showing my app is unsafe
private class SSLTolerentWebViewClient extends WebViewClient {
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed(); // Ignore SSL certificate errors
}
}
Can anyone one suggest me how can I do this so my WebView
can handle https url and Playstore not mark my app as unsafe?
Just for future reference or for anyone else that is facing the same problem! Using Xamarin Forms.
It works, here is the full code I used. It also fixes another bug where the Scroll of the WebView is not working anymore when using Xamarin Shell.
using System;
using Android.Content;
using Android.Views;
using Mobile.Droid.Render;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(WebView), typeof(MyWebViewRenderer))]
namespace Mobile.Droid.Render
{
public class MyWebViewRenderer : WebViewRenderer
{
public MyWebViewRenderer(Context context) : base(context)
{
}
public override bool DispatchTouchEvent(MotionEvent e)
{
Parent.RequestDisallowInterceptTouchEvent(true);
return base.DispatchTouchEvent(e);
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
// Setting the background as transparent
this.Control.SetBackgroundColor(Android.Graphics.Color.Transparent);
if (e.OldElement == null)
{
Control.SetWebViewClient(new MyFormsWebViewClient(this));
}
}
internal class MyFormsWebViewClient : FormsWebViewClient
{
MyWebViewRenderer _renderer;
public MyFormsWebViewClient(MyWebViewRenderer renderer) : base(renderer)
{
_renderer = renderer;
}
public override void OnReceivedSslError(Android.Webkit.WebView view, Android.Webkit.SslErrorHandler handler, Android.Net.Http.SslError error)
{
handler.Proceed();
}
public override void OnPageFinished(Android.Webkit.WebView view, string url)
{
base.OnPageFinished(view, url);
}
public override void OnLoadResource(Android.Webkit.WebView view, string url)
{
base.OnLoadResource(view, url);
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With