Android JS warning / not working in lollipop 5.1
Here is my code that worked great in PRE Lollipop.
public static void alertWebView(String url, Context c) {
final WebView webView = new WebView(c.getApplicationContext());
webView.clearCache(true);
webView.clearHistory();
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setDefaultTextEncodingName("utf-8");
webView.getSettings().setPluginState(PluginState.ON);
webView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
webView.setLongClickable(false);
AlertDialog.Builder builder = new AlertDialog.Builder(c);
builder.setInverseBackgroundForced(true);
builder.setPositiveButton("BezΓ‘r", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
}).setView(webView);
final AlertDialog dialog = builder.create();
webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
return super.onJsAlert(view, url, message, result);
}
});
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
}
});
webView.loadUrl(url);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
dialog.show();
}
}, 1000);
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
}
04-21 11:18: 48.425: W / JsDialogHelper (3997): Unable to create dialog, WebView context is not an activity
html is a button with onclick button and js confirmation.
+3
source to share
No one has answered this question yet
See similar questions:
or similar: