小编Sel*_*ran的帖子

长按从 WebView 保存图像

需要帮忙

我正在尝试通过长按照片从 webview 下载图片,当我使用 Toast 消息测试长按操作时,它起作用了

但它没有下载。

 private View.OnLongClickListener listener=new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            mWebView.setDownloadListener(new DownloadListener() {

                @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                public void onDownloadStart(String url, String userAgent,
                                            String contentDisposition, String mimetype,
                                            long contentLength) {
                    DownloadManager.Request request = new DownloadManager.Request(
                            Uri.parse(url));

                    request.allowScanningByMediaScanner();
                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
                    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Name of your downloadble file goes here, example: Keerthi");
                    DownloadManager dm = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
                    dm.enqueue(request);
                    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); //This is important!
                    intent.addCategory(Intent.CATEGORY_OPENABLE); //CATEGORY.OPENABLE
                    intent.setType("*/*");//any application,any extension
                    Toast.makeText(getContext(), "Downloading …
Run Code Online (Sandbox Code Playgroud)

android image download webview long-press

6
推荐指数
2
解决办法
7260
查看次数

标签 统计

android ×1

download ×1

image ×1

long-press ×1

webview ×1