Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用webview Android下载图像和mp3_Java_Android_Webview_Download_Android Webview - Fatal编程技术网

Java 使用webview Android下载图像和mp3

Java 使用webview Android下载图像和mp3,java,android,webview,download,android-webview,Java,Android,Webview,Download,Android Webview,我需要在Android webView中下载图像(png、jpg、jpeg、gif)和mp3。 当我单击下载mp3按钮或图像按钮时,它不会给出任何响应。 下面是我的代码 @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { progressBar.setVisibility(View.VISIBLE); if(webview.get

我需要在Android webView中下载图像(png、jpg、jpeg、gif)和mp3。 当我单击下载mp3按钮或图像按钮时,它不会给出任何响应。 下面是我的代码

@Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            progressBar.setVisibility(View.VISIBLE);
            if(webview.getUrl().contains(".mp3")){
                DownloadManager.Request request = new DownloadManager.Request(
                        Uri.parse(url));
                request.allowScanningByMediaScanner();
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "download mp3");

                DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                dm.enqueue(request);

            }
            if(url.indexOf("somesite.com") > -1 ) return false;

            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }
我使用的api级别为21

我在清单中也有存储读写权限。 好心帮忙