Using this code to load url.Url
is working fine in android & desktop browser. I have write Android code to show Confirm boxes in android. It's working fine in Nexus and Samsung device but no Confirm boxes shown in Huawei device by giving error in console
"Uncaught TypeError: Cannot call method 'querySelector' of 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); } }