0

I'm currently create an application that have the possibility to updated from own code thanks to a downloaded .apk from a server.

I would like to know if the update/Install of the app is successfull. Because currently the update working fine but i don't know if the installation/update is ok or not, if the installation face a problem or if the user cancel install or somethings else. So i need to have a callback "installFinish(boolean isOk)".

i search for a day but i don't find solution for my problem.

I read lot of things, particulary this :

How to find out when an installation is completed

or this :

Android - Install Application programmatically with result

but is not what i seach. This is my code for update my app

Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file.getAbsoluteFile()), "application/vnd.android.package-archive");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ((Activity) context).startActivity(intent);

EDIT

I tried this https://stackoverflow.com/questions/29175722/how-to-get-onactivityresult-called-from-action-view-intent

but it's not working for me for two reason i think:

  • I don't know whether the user pressed Cancel

  • onActivityResult is never call after updated the same app, maybe because it's the same app which updated the app who launch the intent is kill. ?

Maybe the last reason it's the same reason why i don't receive broadcastevent such as listening for ACTION_PACKAGE_ADDED in the app who launch the update.

Maybe i can call the method when the first time the application is launch, it's like install is successfully because the app is started.

Community
  • 1
  • 1
Slasch
  • 275
  • 1
  • 6
  • 20
  • 1
    Meanwhile you could have told us what THE problem is with installing a new version of the apk by the app itself. – greenapps Sep 04 '15 at 15:25
  • I don't have a problem with installing/updating app, it's working fine, but i need to know if the installation from my app of the new apk of my app was successfully. Maybe during installation the user kill install or not enought space on device, or other problem... so i need to know if install was successfully or not because i need to call a method `installFinish(boolean isOk)` – Slasch Sep 07 '15 at 06:34
  • 1
    You did not describe THE problem. Where/who would (you want) to call that method? Which app? When? – greenapps Sep 07 '15 at 06:58
  • Oh sorry for my misunderstanding. I will try to be more clearly. I need to call that methode in the app which launch the intent to be updated, because the nethod installFinish take 3 elements `installFinish(AndroidPrincipal androidPrincipal, int applicationVersion_id, Boolean isOk);` and i have a value for `androidPrincipal` and `applicationVersion_id` only in this app, because after updated the app i don't have this value. I hope to be clear – Slasch Sep 07 '15 at 07:29
  • 1
    Not clear. ` I need to call that methode in the app which launch the intent to be updated`. Are you speaking about an app that launches such an intent to install another apk of itself? Lets handle this step by step. – greenapps Sep 07 '15 at 12:14
  • Thanks for your answer greenapps. I speak about an app that launches such an intent to update itself. – Slasch Sep 07 '15 at 12:19
  • 1
    And in which instance of your app you want to call installFinish() ? In the old instance or the new instance? Realise that the old instance is killed before the new apk is installed. There is no new instance of your app unless the user starts it again. You never spoke about THAT problem. THE problem! – greenapps Sep 07 '15 at 12:22
  • Ok thanks greenapps that clear for me. Like you can see in my edit, i think about this. So my app is kill during the install, so is not possible to do what i want. – Slasch Sep 07 '15 at 12:30

1 Answers1

1

Heres a work around which we use: Implement a dummy provider and override onUpgrade().onUpgrade is called whenever database is upgraded.U will need maintain one to one mapping between database version and app version.

rupesh jain
  • 3,410
  • 1
  • 14
  • 22
  • 'onUpgrade is called whenever app is upgraded.'. Don't you mean 'when database version changed'? – greenapps Sep 04 '15 at 15:38
  • @greenapps yes whenever database is upgraded.If you maintain one-to-one mapping it will be as good as app getting upgraded. – rupesh jain Sep 04 '15 at 16:01
  • I don't have database in my app, i just call a C# webservice with the current version and it's send the apk of the last version of my app. – Slasch Sep 07 '15 at 06:51
  • `I don't have database in my app`. My god he said you write three code lines to implemnent a dummy database. – greenapps Sep 07 '15 at 12:19