I have an android apk file hosted in iis 7 which I would like to download and install from within an android app. I am relying heavily on the code in this question, but I am getting a fileNotFound exception at InputStream is = con.getInputStream();
I am able to download the apk file from within a browser both on my desktop and on the phone (Samsung galaxy Nexus) and I have added the apk mime type to iis.
Here is my code.
protected Void doInBackground(Void... params) {
try {
URL url = new URL("http://android.atomweb.net.au/CasLite.apk");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.connect();
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "app.apk");
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = con.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")),
"application/vnd.android.package-archive");
startActivity(intent);
} catch (IOException e) {
Log.d("Error", e.getLocalizedMessage());
}
return null;
}
When I post a break point in and look and the connection response code after the connection has been made but before the getInputStream, its 405.