我正在开发 Galaxy Note 10.1
下载动作启动java spring 动作。
此下载操作可在 PC、移动设备浏览器中进行
问题是 Galaxy Note 10.1 内置浏览器
这个浏览器的 userAgent 是
“Mozilla/5.0 (Linux; U; Android 4.0.4; ko-kr; SHW-M480W Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) 版本/4.0 Safari/534.30”
而android的下载方式是
mWebView.setDownloadListener(new DownloadListener(){ public void onDownloadStart(String url, String sUserAgent, String contentDisposition, String mimetype, long contentLength) { URL urls = null; String fileUrl = ""; String mPath = ""; Log.v( "sUserAgent", sUserAgent);
String condition[] = contentDisposition.split("=");
String x = condition[1];
Log.d("test",x);
try {
fileUrl = URLDecoder.decode(x, "UTF-8");
} catch(Exception e) {
e.printStackTrace();
}
try {
urls = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
String fileName[] = url.split("/");
Log.d("test", url);
try {
HttpURLConnection conn= (HttpURLConnection)urls.openConnection();
conn.setDoOutput(true);
conn.connect();
mPath = Environment.getExternalStorageDirectory()+"/Download/";
String chkPath = Environment.getExternalStorageDirectory()+"/Download/"+fileUrl;
File chkFile = new File(chkPath);
if(chkFile.exists() == true){}
else {
File f = new File(mPath);
f.mkdirs();
File OutputFile = new File(f, fileUrl);
FileOutputStream fos = new FileOutputStream(OutputFile);
InputStream is = conn.getInputStream();
byte[]buffer = new byte[24576];
int len1 = 0;
while((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(getApplicationContext(), "DOWNLOAD COMPLETED", 0).show();
File files = new File(mPath+fileUrl);
Log.e("msg",mPath+fileUrl+"");
Intent intent = new Intent(Intent.ACTION_VIEW);
String mimes = fileUrl.substring(fileUrl.length()-3, fileUrl.length());
if(mimes.equals("hwp")) {
intent.setDataAndType(Uri.fromFile(files), "application/x-hwp");
} else {
intent.setDataAndType(Uri.fromFile(files), "application/"+mimes);
}
startActivity(intent);
}
});
春季下载动作是
字符串 mimetype = "application/x-msdownload";
response.setContentType(mimetype);
response.setHeader("fileName", fvo.getFileStreCours()+fvo.getStreFileNm());
setDisposition(fvo.getOrignlFileNm(), request, response);
response.setContentLength(fSize);
BufferedInputStream in = null;
BufferedOutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(uFile));
out = new BufferedOutputStream(response.getOutputStream());
FileCopyUtils.copy(in, out);
out.flush();
response.flushBuffer();
} catch (Exception ex) {
// Connection reset by peer: socket write error
log.debug("IGNORED: " + ex.getMessage());
} finally {
if (in != null) {
try {
in.close();
} catch (Exception ignore) {
log.debug("IGNORED: " + ignore.getMessage());
}
}
if (out != null) {
try {
out.close();
} catch (Exception ignore) {
log.debug("IGNORED: " + ignore.getMessage());
}
}
}
此文件正在从 NAS 下载
但 android 没有访问 web 的响应缓冲区
在android中,制作了0字节文件。
如何访问 web 响应缓冲区中的缓冲区和下载文件?
附言。网络服务不允许打开网址,所以我不能使用重定向