portfoliobuilder
portfoliobuilder

Reputation: 7856

How to update application automatically; Android

I am building a launcher application that I would like to update over the air. I created a service class that successfully checks and compares App version numbers to determine whether an update is needed. If the compared apk version is higher than current version, I download the apk from my cloud server, and then bring up a dialog to install it.

The conflict I am facing is that the update will not install. I receive an error "An existing package by the same name with a conflicting signature is already installed". I am beginning to wonder if my methodology is correct. How can I resolve this? Here is what I am doing.

Once an update is confirmed, I display a dialog and on press of the confirmation button I use an Intent to parse the app URL

Intent i = new Intent(Intent.ACTION_VIEW);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setData(Uri.parse(appUrl));
startActivity(i);
finish();

This actually posts a notification that I have to click and press install on. Once I do, it attempts to install, but then gives me the error on conflicting signatures.

Ideally, I just want it to install without having to see the notification. Thank you in advance.

Upvotes: 2

Views: 1176

Answers (3)

Gaurav Srivastava
Gaurav Srivastava

Reputation: 363

You need not necessarily use Playstore or any other app hosting service to manage your application upgrades. Your users should enable: Install from un-identified sources (on their android handset)

For auto-upgrade you must release all your APK's with the same Signature. If you just build and run the application from Eclipse, the APK file generated in DIST folder is signed with Debug key (the default key of each machine)

Now if you build the same Code from different machine, the debug key values will be different and you would get the error: "An existing package by the same name with a conflicting signature is already installed" while installing the new APK

Here are a few solutions to it:

  1. Always release the APK for auto-upgrade from same machine (this is definitely impossible)
  2. Sign all the APK's with same signature. In Eclipse: Right click on project > Android Tools > Export Signed Application Package

Upvotes: 2

Forgen
Forgen

Reputation: 48

I have seen the "same signature" error when deploying directly from Android Debug Bridge. I am thinking you will not be successful in this approach, because:

  1. Android security always requires user authorization to install updates (unless you are rooted, or are part of the system like Google Play Store auto-update.
  2. Google play always has to kill the running process to update it. This probably will be ok if you service and the application are actually separate installations (i.e. two apks).
  3. The same signature error I received in ADB is usually when the system is requiring me to completely uninstall the original signature application. Two applications with the same signature cannot be installed concurrently; something is triggering Android to not perform an 'upgrade' of the same package.

Here are the allowable ways to perform an upgrade: Is there a way to automatically update application on Android?

Upvotes: 1

Jeffrey Mixon
Jeffrey Mixon

Reputation: 13616

You are setting it up almost correctly, but you should also set the data type:

i.setType("application/vnd.android.package-archive")

Additionally, do not call finish() after startActivity(). It is not necessary and might cause issues with the new Intent.

Your signature conflict is another problem. See this answer. The APK you are trying to install is signed with a different key that the currently installed one.

Finally, there is no way to install an APK without the user's explicit interaction (unless you have root, of course). This is intention for security reasons.

Upvotes: 1

Related Questions