我正在尝试使用自定义WebChromeClient,但对于android marshmallow和nougat中的某些URL,它在logcat中显示我的错误,并且不加载URL,但它对于pre marshmallow工作正常。
错误:
W / cr_AwContentsClient:拒绝在没有用户的情况下启动意图 手势
错误是什么意思?我该怎么处理呢?
网络视图:
@SuppressLint("SetJavaScriptEnabled")
public class MyWebView extends BaseWebView {
public BrowserWebView(Context context, AttributeSet attrs) {
super(context, attrs);
getSettings().setJavaScriptEnabled(true);
setWebChromeClient(new WebChromeClient());
}
}
活动:
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();
}
}
活动布局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>