此代码在从 apache 服务器下载时有效,没问题。但是在测试使用安装在win7上的iis 7.5 currenlty时。它似乎不适用于 getInputStream(); 尽管在调试并将其粘贴到浏览器中时会显示文件的完整地址,但会开始下载 apk
看了本站和网上都加了 MIME TYPE .apk application/vnd.android.package-archive
try {
URL url = new URL(prefs.getString("server_address", null) + "/updates/filename.apk");
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "filename.apk");
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
} catch (IOException e) {
Toast.makeText(context, "error!", Toast.LENGTH_LONG).show();
}