gpt4 book ai didi

android - WebView & 下载管理器

转载 作者:行者123 更新时间:2023-11-30 01:41:06 25 4
gpt4 key购买 nike

我正在制作一个应用程序,其工作是加载一个特定的网站。除了下载文件外,一切正常。

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adviser = (WebView) findViewById(R.id.webView);
getActionBar().hide();
adviser.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);

adviser.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {

Request request = new Request(Uri.parse(url));

request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS,
customizeurl(contentDisposition));
DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
dm.enqueue(request);

Toast.makeText(getApplicationContext(), "downloading",
Toast.LENGTH_LONG).show();
}
});
return true;
}
});

adviser.getSettings().setJavaScriptEnabled(true);
adviser.getSettings().setSupportZoom(true);
adviser.getSettings().setAllowFileAccess(true);
adviser.getSettings().setAllowUniversalAccessFromFileURLs(true);

adviser.getSettings().setUseWideViewPort(true);
adviser.getSettings().setLoadWithOverviewMode(true);
adviser.setVerticalScrollBarEnabled(true);
adviser.setHorizontalScrollBarEnabled(false);
adviser.getSettings().setAppCacheEnabled(true);
adviser.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
adviser.getSettings().setSupportMultipleWindows(true);

adviser.getSettings().setUserAgentString("Mozilla");
adviser.loadUrl("http://localhost/www/site/login");
}

url: localhost/www/site/download?action=newaction&dl=folder\subfolder\subsubfolder\1449822583856.jpg

uri: localhost/www/site/download?action=newaction&dl=folder\subfolder\subsubfolder\1449822583856.jpg

userAgent: Mozilla//无论我用什么作为代理都行不通

contentDisposition: attachment;filename=1449822583856.jpg

模仿类型:图像/jpeg

内容长度:-1

它将我的主页下载为 php 文件,而不是我的 jpg。有任何想法吗?感谢您的帮助:)

编辑:Content-Length 可能有问题?或者可能是一些 session 问题?

最佳答案

很明显会下载一个php文件,因为你提供的url没有包含文件的直接地址

URL = localhost/www/site/download?action=newaction&dl=folder\subfolder\subsubfolder\1449822583856.jpg

因此在浏览器中输入它会显示图像,但地址不属于任何文件下载

关于android - WebView & 下载管理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34491636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com