2

I'm trying to use custom WebChromeClient, but for some URL's in android marshmallow and nougat it show's me below error in logcat and don't load URL, but it's working fine for pre marshmallow.

The error:

W/cr_AwContentsClient: Denied starting an intent without a user gesture

What is the meaning the error? How should I handle it?

The webview:

@SuppressLint("SetJavaScriptEnabled")
public class MyWebView extends BaseWebView {
    public BrowserWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
        getSettings().setJavaScriptEnabled(true);
        setWebChromeClient(new WebChromeClient());
    }
}

The activity :

public class MyActivity extends Activity {

    private MyWebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_browser);
        webView = (MyWebView) findViewById(R.id.my_web_view);

        webView.loadUrl("https://.../");
    }

    @Override
    public void onBackPressed() {
        // Check if the key event was the Back button and if there's history
        if (webView != null && webView.canGoBack()) {
            webView.goBack();
            return;
        }

        super.onBackPressed();
    }
}

Activity layout XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".view.activity.MyActivity">

    <com.test.MyWebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/my_web_view"/>

</RelativeLayout>
Shervin Gharib
  • 728
  • 2
  • 14
  • 29
  • i think you could be fine adding webview.setWebViewClient(new WebViewClient()); before setWebChromeClient – MatPag Sep 26 '16 at 10:51
  • 1
    refer this [Denied starting an intent without a user gesture](http://stackoverflow.com/questions/33048945/denied-starting-an-intent-without-a-user-gesture-webview-android) – sajan Sep 26 '16 at 10:51
  • @Mat yeah, but I don't want to set WebViewClient, because it removes address bar and other chrome stuff. – Shervin Gharib Sep 26 '16 at 10:59
  • @exshinigami You could use a hand-made EditText as address bar or try to extend WebViewClient and prevent the Chrome address bar removal (i honestly never tried this, so i don't know if it's really possible or not) – MatPag Sep 26 '16 at 12:15

0 Answers0