Using this code to download url.Url works fine in the android and desktop browser. I am writing Android code to show the "Verify" checkboxes in android. It works great on Nexus and Samsung devices, but doesn’t display the confirmation fields shown on the Huawei device, causing an error in the console
"Uncaught TypeError: cannot call 'querySelector' method from null", source: http: //abc/build/js/frontend-abc.js (16683)
private class WebViewChromeClient extends WebChromeClient { @Override public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result) { new AlertDialog.Builder(context) .setTitle(getString(R.string.str_confirmation_title)) .setMessage(message) .setPositiveButton(getString(R.string.str_ok), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { result.confirm(); } }).setCancelable(false).create().show(); return true; } @Override public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) { new AlertDialog.Builder(context) .setTitle(getString(R.string.str_confirmation_title)) .setMessage(message) .setPositiveButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { result.confirm(); } }).setNegativeButton(getString(R.string.str_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { result.cancel(); } }).create().show(); return true; } @Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, final JsPromptResult result) { final LayoutInflater factory = LayoutInflater.from(context); final View v = factory.inflate(R.layout.layout_alertdialog, null); ((TextView) v.findViewById(R.id.tv_messagealert)).setText(message); showJSPromptAlert(v, result); return true; } } private void showJSPromptAlert(View v, final JsPromptResult result) { AlertDialog.Builder builder = new AlertDialog.Builder(context) .setTitle(getString(R.string.str_confirmation_title)) .setView(v) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { result.confirm(getString(R.string.str_ok)); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { result.cancel(); } }) .setOnCancelListener( new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { result.cancel(); dialog.cancel(); } }); alert11 = builder.create(); alert11.show(); } WebView wvContainer = (WebView) findViewById(R.id.wv_container); private void loadUrl(String url) { wvContainer.setInitialScale(1); wvContainer.setWebViewClient(new MyBrowser()); adjustWebViewSettings(); wvContainer.canGoBack(); adjustWebViewForLatestVersion(); wvContainer.setWebChromeClient(new WebViewChromeClient()); wvContainer.loadUrl(url); } private void adjustWebViewSettings() { wvContainer.getSettings().setJavaScriptEnabled(true); wvContainer.getSettings().setSupportZoom(true); wvContainer.getSettings().setAllowContentAccess(true); wvContainer.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); wvContainer.getSettings().setSupportMultipleWindows(true); wvContainer.getSettings().setDomStorageEnabled(true); wvContainer.getSettings().setAppCacheEnabled(true); wvContainer.getSettings().setUseWideViewPort(true); if (Build.VERSION.SDK_INT >= 21) { wvContainer.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } } private void adjustWebViewForLatestVersion() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { wvContainer.getSettings().setAllowUniversalAccessFromFileURLs(true); wvContainer.getSettings().setAllowFileAccessFromFileURLs(true); wvContainer.getSettings().setAllowFileAccess(true); wvContainer.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } }
javascript jquery android android-webview android-alertdialog
Erum Jan 9 '17 at 11:42 on 2017-01-09 11:42
source share