WebView call action:
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView wView, String url)
{
if (url.startsWith("mailto:") || url.startsWith("tel:") || url.startsWith("geo:")) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
startActivity(intent);
return true;
} else if (url.startsWith("whatsapp:")) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
return true;
}
return false;
}
});
Webview zoom option:
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setLayoutAlgorithm(webView.getSettings().getLayoutAlgorithm());
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setEnableSmoothTransition(true);
Enable download option in webview:
Java:
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(final String url, final String userAgent, String contentDisposition, String mimetype, long contentLength) {
//Checking runtime permission for devices above Marshmallow.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
Log.v("WebBrowser", "Permission is granted");
downloadDialog(url, userAgent, contentDisposition, mimetype);
} else {
Log.v("WebBrowser", "Permission is revoked");
//requesting permissions.
ActivityCompat.requestPermissions(Web_browser.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
} else {
//Code for devices below API 23 or Marshmallow
Log.v("WebBrowser", "Permission is granted");
downloadDialog(url, userAgent, contentDisposition, mimetype);
}
}
});add more:String[] permissionsStorage = {Manifest.permission.READ_EXTERNAL_STORAGE}; int requestExternalStorage = 1; int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE); if (permission != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, permissionsStorage, requestExternalStorage); } if(!isNetworkAvailable(Web_browser.this)){ webView.setVisibility(View.GONE); layNonet.setVisibility(View.VISIBLE); }else{ webView.setVisibility(View.VISIBLE); layNonet.setVisibility(View.GONE); }
Manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />