I am trying to make a WebView based Android app. It's found that when ever I try to sign in Google account i get a error. I am using the default WebView in Java, and has added some additional codes to make it more functional like enabling JS, Cookies, file upload and download. The code I used in OnCreate also tried this question
if (query.getString("query", "").contains("https://")) {
webview1.loadUrl(query.getString("query", ""));
}
else {
webview1.loadUrl("https://qmamu.com/search?q=".concat(query.getString("query", "").concat("&from=web")));
}
webview1.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
progressBar.setProgress(newProgress);
}
```
@Override
public void onReceivedIcon(WebView view, Bitmap icon) {
super.onReceivedIcon(view, icon);
favicon.setImageBitmap(icon);
}
});
webview1.getSettings().setJavaScriptEnabled(true);
webview1.getSettings().setUseWideViewPort(true);
webview1.getSettings().setBuiltInZoomControls(false);
webview1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webview1.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity (intent);
}
});
webview1.getSettings().setAllowFileAccess(true);
webview1.getSettings().setLoadWithOverviewMode(true);
webview1.getSettings().setUseWideViewPort(true);
webview1.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webview1.getSettings().setDomStorageEnabled(true);
webview1.getSettings().setSaveFormData(true);
webview1.getSettings().setLoadWithOverviewMode(true); webview1.getSettings().setUseWideViewPort(true); final WebSettings webSettings = webview1.getSettings(); final String newUserAgent; newUserAgent = "Mozilla/5.0 (Android) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"; webSettings.setUserAgentString(newUserAgent);
if (1 == 2) {
startActivityForResult(cam, REQ_CD_CAM);
Intent _intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
_intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName());
_intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
_intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
sp.startListening(_intent);
}
webview1.setWebChromeClient(new WebChromeClient(){
@Override
public void onPermissionRequest(PermissionRequest request){
// Generally you want to check which permissions you are granting
request.grant(request.getResources());
}
});
webSettings.setJavaScriptCanOpenWindowsAutomatically(true); if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { webSettings.setAllowFileAccessFromFileURLs(true); webSettings.setAllowUniversalAccessFromFileURLs(true); }
webview1.getSettings().setSavePassword(true);
webview1.setWebChromeClient(new WebChromeClient() {
// For 3.0+ Devices
protected void openFileChooser(ValueCallback uploadMsg, String acceptType) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE);
}
public boolean onShowFileChooser(WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
if (uploadMessage != null) {
uploadMessage.onReceiveValue(null);
uploadMessage = null; } uploadMessage = filePathCallback; Intent intent = fileChooserParams.createIntent(); try {
startActivityForResult(intent, REQUEST_SELECT_FILE);
} catch (ActivityNotFoundException e) {
uploadMessage = null; Toast.makeText(getApplicationContext(), "Cannot Open File Chooser", Toast.LENGTH_LONG).show(); return false; }
return true; }
//For Android 4.1 only
protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
mUploadMessage = uploadMsg; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "File Browser"), FILECHOOSER_RESULTCODE);
}
protected void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
}
});
CookieManager.getInstance().setAcceptCookie(true);
{
android.graphics.drawable.GradientDrawable SketchUi = new android.graphics.drawable.GradientDrawable();
SketchUi.setColor(0xFFFFFFFF);
float lt = getDip(0);
float rt = getDip(0);
float rb = getDip(43);
float lb = getDip(43);
SketchUi.setCornerRadii(new float[]{
lt,lt,rt ,rt,rb,rb ,lb,lb });
linear7.setElevation(getDip(30));
linear7.setBackground(SketchUi);
}
webview1.getSettings().setBuiltInZoomControls(true);webview1.getSettings().setDisplayZoomControls(false);
The Error message in WebView
Can you tell me a code or any other method to avoid this error without changing whole application program.