0
ダウンロードは正常に動作しますが、ファイル名と同じ名前を付けてダウンロードする方法を教えてください。webviewを使用してダウンロードしたファイルの名前を正しく指定するにはどうすればよいですか?
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
//for downloading directly through download manager
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "downloads");
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
}
});
ファイルの同じ名前を取得する方法はありますか? –
はい使用することができます –
final String [] separated = url.split( "/"); final文字列myFile = separated [separated.length - 1];次に、request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS、myFile);を呼び出します。 –