X
X
xaiponews2020-11-17 14:27:47
Android
xaiponews, 2020-11-17 14:27:47

How to specify that the download is carried out in the gallery?

I can't figure out how to specify that the download is carried out in the gallery from WebViwe

String downloadImg = webViewHitTestResult.getExtra();
                    if (URLUtil.isValidUrl(downloadImg)){
                        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downloadImg));
                        request.allowScanningByMediaScanner();
                        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION);
                        DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                        downloadManager.enqueue(request);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xaiponews, 2020-11-17
@xaiponews

Decision

@Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);

        final WebView.HitTestResult webViewHitTestResult = webView.getHitTestResult();
        if (webViewHitTestResult.getType() == WebView.HitTestResult.IMAGE_TYPE || webViewHitTestResult.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE){
            
            menu.add("Сохранить изображение").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {

                    String downloadImg = webViewHitTestResult.getExtra();
                    if (URLUtil.isValidUrl(downloadImg)){
                        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downloadImg));
                        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
                        request.setAllowedOverRoaming(false);
                        request.setTitle("GadgetSaint Downloading " + "Sample" + ".png");
                        request.setDescription("Downloading " + "Sample" + ".png");
                        request.setVisibleInDownloadsUi(true);
                        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/GadgetSaint/"  + "/" + "Sample" + ".png");
                        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION);
                        DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                        downloadManager.enqueue(request);
                    }
                    return false;
                }
            });
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question