0

I have been trying to implement an upgrade plan for my Android app which will not be released on the Android market.

The designed application work flow is as follows:

  1. User is validated at login and the main menu activity is launched.
  2. A request is sent from the main menu activity to my website for latest version code value (Stor in an SQL database on the server).
  3. The returned version code value is compared against the version code value of the apk installed on the device.
  4. If the returned version code value is different, then the new apk file which is located on the server is downloaded and installed.

It is also important to make sure that the following tasks have been completed before the upgrade work flow will work.

  1. The new version of the apk must be compiled singed for release with an updated versionCode value
  2. The value stored in the website database for the versionCode value must be updated
  3. The newly compiled apk file must be uploaded to the correct location on the web server

I have implemented the first 3 stages of my work flow but when I try to implement the 4th part I end up getting the "Parse Error: There is an issue parsing the package" error.

Below is the offending code:

protected void upgradeApplication() {
    StringBuilder urlBuilder = new StringBuilder(getString(R.string.website_ip) + "/" + getString(R.string.application_middleware) + "/" + getString(R.string.apk_folder) + "/"); 

    File file = new File(urlBuilder.toString(), getString(R.string.apk_file));

    Intent intent = new Intent(Intent.ACTION_VIEW);

    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");

    startActivity(intent);
}

I have tested that the apk will install correctly by downloading the apk directly though the devices web browser and installing it from the downloads folder. But when I try to install from within the application I get the posted error.

"Parse Error: There is aproblem parsing the package"

Any help would be appreciated

Comic Coder
  • 519
  • 1
  • 9
  • 32
  • are you storing it in getFileDir ? – Vipul Jun 18 '12 at 11:27
  • You mean storing the apk? I have forced the application to use internal memory only as I cannot be sure the users will have an SD card installed – Comic Coder Jun 18 '12 at 11:31
  • Also I thought that the following line of code would pull the file from the website. `File file = new File(urlBuilder.toString(), getString(R.string.apk_file));` where urlBuilder contains the link to the apk file – Comic Coder Jun 18 '12 at 11:34
  • Ok I added `if(file.exists()) { // Start intent }` and it does not exist it skips the code inside the code block – Comic Coder Jun 18 '12 at 11:45

2 Answers2

1

If with this line

File file = new File(urlBuilder.toString(), getString(R.string.apk_file));

you're trying to download the file by passing the url as an argument, then it won't work. The File constructor cannot download a file.

You should use an AsyncTask to download the apk, wait before it's done then only you can install it.

Community
  • 1
  • 1
Dalmas
  • 26,409
  • 9
  • 67
  • 80
  • Hi Dalmas I have implemented the Async Task as shown in the link you provide and everything seems to work correctly but I still get the Parse error at the end. Looking in the log file I get the following error: Unable to open zip '/data/data/uk.estrix.android.m3sms/files/Mobile M3 SMS Sales Automation': Permission denied. I can post the whole log file if required. – Comic Coder Jun 18 '12 at 14:36
1

If you are storing your .apk file in private internal storage then it needs Context.MODE_WORLD_READABLE permission.

Below snippet will help you.

String outFileName = path+"/<Application_Name>.apk";
OutputStream myOutput = openFileOutput("<Application_Name>.apk", Context.MODE_WORLD_READABLE);

And then to install it,

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path+"/<Application_Name>.apk")), "application/vnd.android.package-archive");
startActivity(intent);
Vipul
  • 27,808
  • 7
  • 60
  • 75
  • Hi Vipul I tried to add you on face book (Iain Blackwood) I wanted some clarification about path locations on the internal memory – Comic Coder Jun 18 '12 at 13:46