Issue
Suppose I'm using a URL in webview http://demo.io and this URL has a button of camera and when I click on that camera button then my URL became http://demo.io/captureImage. Then I have an issue when I check the url of webview then it shows only http://demo.io not showing http://demo.io/captureImage so how I can get this URL in Android. Because this URL has an image and I wanna save this image. When this URL (http://demo.io/captureImage) runs on chrome and I capture the image then captured image downloaded but in Android webview image after capturing not downloading. Please suggest me appropriate answer or code
Solution
You can add a download listner to webivew and download the image from the url as shown below
webview.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimeType);
//------------------------COOKIE!!------------------------
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
//------------------------COOKIE!!------------------------
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType));
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show();
}
Answered By - Hasif Seyd
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.