The following minor modification fixed my problem:
while ((count = input.read(data)) > 0)
Question
I am trying to download an install a .apk file from an application. Here are 3 different situations:
1. From Eclipse to Tablet via adb > Run application > No problems
2. From Eclipse > Sign & Export > Transfer .apk file to tablet via USB > Install & Run application > No problems
3. From Eclipse > Sign & Export > (The same file from 2.) Upload .apk file to a server > Download .apk file from application > Try to install > "There is a problem parsing the package"
code for downloading the application:
private class DownloadFile extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... sUrl) {
try {
URL url = new URL(sUrl[0]);
URLConnection connection = url.openConnection();
connection.connect();
// this will be useful so that you can show a typical 0-100% progress bar
int fileLength = connection.getContentLength();
// download the file
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory() + File.separator + "Download" + File.separator + "Design102.apk");
byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
publishProgress((int) (total * 100 / fileLength));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Why am I getting "There is a problem parsing the package" error for the same .apk file after downloading?
La solution
The following minor modification fixed my problem:
while ((count = input.read(data)) > 0)