Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.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 DownloadListener中获取文件名以将其放入下载程序文件_Java_Android_Webview - Fatal编程技术网

Java 如何在webview DownloadListener中获取文件名以将其放入下载程序文件

Java 如何在webview DownloadListener中获取文件名以将其放入下载程序文件,java,android,webview,Java,Android,Webview,我有一个webview应用程序,它是为我的本地网站开发的,所以 当我点击一个链接下载任何文件时,它是下载的,但名称是“filename”,就像我在代码中选择的一样 那么有没有办法获取下载的文件名并将其设置为下载的名称呢 请编辑我的代码,并为我过去,因为我是一个乞丐在android编程 这是我下载的侦听器代码 谢谢大家 webview.setDownloadListener(新的DownloadListener(){ @凌驾 public void onDownloadStart(字符串url、

我有一个webview应用程序,它是为我的本地网站开发的,所以

当我点击一个链接下载任何文件时,它是下载的,但名称是“filename”,就像我在代码中选择的一样

那么有没有办法获取下载的文件名并将其设置为下载的名称呢

请编辑我的代码,并为我过去,因为我是一个乞丐在android编程

这是我下载的侦听器代码

谢谢大家

webview.setDownloadListener(新的DownloadListener(){
@凌驾
public void onDownloadStart(字符串url、字符串userAgent、字符串contentDisposition、字符串类型、长contentLength){
DownloadManager.Request=newdownloadmanager.Request(Uri.parse(url));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.request.VISIBILITY\u VISIBLE\u NOTIFY\u完成);
setDestinationNexternalPublicDir(Environment.DIRECTORY_下载,“文件名”);
DownloadManager=(DownloadManager)getSystemService(下载服务);
if(manager!=null){
排队(请求);
Toast.makeText(getApplicationContext(),“Toast.LENGTH”show();
}
}
});

}
是否尝试在内容处置标题中设置文件名


类似于
request.addRequestHeader(“内容处置”、“附件;文件名=\”filename.txt\”)

是否尝试在内容处置标题中设置文件名


类似于
request.addRequestHeader(“内容处置”、“附件;文件名=\”filename.txt\”)

如果是Get url。文件名将是url的结尾

如果是POST方法。文件名将在响应头中商定


希望能帮助您。

如果是Get url,则文件名将是url的结尾

如果是POST方法。文件名将在响应头中商定


希望能帮助您。

我找到了我需要的代码,谢谢大家

我希望能帮助一些人

webview.setDownloadListener(新的DownloadListener(){
@凌驾
public void onDownloadStart(字符串url、字符串userAgent、字符串contentDisposition、字符串mimeType、长contentLength){
DownloadManager.Request=newdownloadmanager.Request(Uri.parse(url));
request.setMimeType(mimeType);
//------------------------饼干------------------------
字符串cookies=CookieManager.getInstance().getCookie(url);
addRequestHeader(“cookie”,cookies);
//------------------------饼干------------------------
addRequestHeader(“用户代理”,userAgent);
请求。设置描述(“بتتتملاللف…”);
setTitle(URLUtil.guessFileName(url、contentDisposition、mimeType));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.request.VISIBILITY\u VISIBLE\u NOTIFY\u完成);
request.setdestinationnexternalpublicdir(Environment.DIRECTORY_下载,URLUtil.guessFileName(url,contentDisposition,mimeType));
DownloadManager dm=(DownloadManager)getSystemService(下载服务);
dm.enqueue(请求);
Toast.makeText(getApplicationContext(),“Toast.LENGTH”show();
}

});我找到了我需要的代码,谢谢每一个

我希望能帮助一些人

webview.setDownloadListener(新的DownloadListener(){
@凌驾
public void onDownloadStart(字符串url、字符串userAgent、字符串contentDisposition、字符串mimeType、长contentLength){
DownloadManager.Request=newdownloadmanager.Request(Uri.parse(url));
request.setMimeType(mimeType);
//------------------------饼干------------------------
字符串cookies=CookieManager.getInstance().getCookie(url);
addRequestHeader(“cookie”,cookies);
//------------------------饼干------------------------
addRequestHeader(“用户代理”,userAgent);
请求。设置描述(“بتتتملاللف…”);
setTitle(URLUtil.guessFileName(url、contentDisposition、mimeType));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.request.VISIBILITY\u VISIBLE\u NOTIFY\u完成);
request.setdestinationnexternalpublicdir(Environment.DIRECTORY_下载,URLUtil.guessFileName(url,contentDisposition,mimeType));
DownloadManager dm=(DownloadManager)getSystemService(下载服务);
dm.enqueue(请求);
Toast.makeText(getApplicationContext(),“Toast.LENGTH”show();
}

});我有很多不同的文件,每个页面都有不同的文件名,所以我想要一个与原始文件名一样的自动命名。我有很多不同的文件,每个页面都有不同的文件名,所以我想要一个与原始文件名一样的自动命名。