Reputation: 113
I want to ask a question about downloading Apk with programmatically in Android. When i give url over http, Apk is not downloaded to my telephone. But changing URL with https works to download the APK with successufully. What is the reason of this? Also, downloading url is hidden over https website.
try {
URL url = new URL("http://....../LinaSoft_1_0_4.Apk");
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.connect();
String PATH = Environment.getExternalStorageDirectory()+"/Download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file,"LinaSoft_1_0_4.apk");
Log.d("output",outputFile.toString());
File dosyalar = new File(PATH);
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
int total_size = c.getContentLength();
byte[] buffer = new byte[1024];
int len1 = 0;
int per = 0;
int downloaded=0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
downloaded +=len1;
per = (int) (downloaded * 100 / total_size);
publishProgress(per);
}
fos.close();
is.close();
Log.d("Boyut",String.valueOf(total_size));
OpenNewVersion(PATH);
flag = true;
} catch (IOException e) {
Log.d( "Update Error: " , e.getMessage());
flag = false;
}
return flag;
}
Upvotes: 0
Views: 842