Is it possible to ensure that when opening the url of the image through WebView , you can download it to your device?

    2 answers 2

    I think the point is this: the image loaded into the web has the URL to which it is stored on the server. You can try to parse the page that is loaded into the web view (xs, I personally have not tried it) and pull the address of the picture. After that, download the picture at this address unless of course the site will give them away.

    • It’s not necessary to parse everything, it will be necessary to write on javascript and if you click on a picture, take it and save the picture to a memory card, like that. - Gorets
    • may well be. The main thing that the author understood the vector of thought is correct) The fact that it is possible I think is beyond doubt. - DroidAlex

    In webview

      myWebView.addJavascriptInterface(new JavascriptInterface(getActivity()), "imagelistner"); myWebView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { view.getSettings().setJavaScriptEnabled(true); super.onPageStarted(view, url, favicon); } @Override public void onPageFinished(WebView view, String url) { view.getSettings().setJavaScriptEnabled(true); super.onPageFinished(view, url); addImageClickListner(); } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { myWebView.setVisibility(View.INVISIBLE); } }); 

    and to class

      private void addImageClickListner() { myWeb.loadUrl("javascript:(function(){" + "var objs = document.getElementsByTagName(\"img\"); " + "for(var i=0;i<objs.length;i++) " + "{" + " objs[i].onclick=function() " + " { " + " window.imagelistner.openImage(this.src); " + " } " + "}" + "})()"); } public class JavascriptInterface { private Context context; public JavascriptInterface(Context context) { this.context = context; } @android.webkit.JavascriptInterface public void openImage(String img) { DownloadManager.Request rqtRequest = new DownloadManager.Request(Uri.parse(img)); rqtRequest.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); ((DownloadManager) getSystemService(DOWNLOAD_SERVICE)).enqueue(rqtRequest); } } 

    In openImage, you can do anything with the string I sent to the standard loader