Java 使用webview Android下载图像和mp3
我需要在Android webView中下载图像(png、jpg、jpeg、gif)和mp3。 当我单击下载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
@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
我在清单中也有存储读写权限。
好心帮忙