我正在开发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,与Gecko一样)Version / 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);
}
});
Spring 天的下载动作是
String 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中,maked 0字节文件 .
如何在web的响应缓冲区中访问缓冲区和下载文件?
PS . Web服务不允许打开url,所以我不能使用重定向