7 Replies Latest reply on Feb 7, 2013 1:05 AM by Daniel Lindberg

    MC40 install apk programmatically

    Daniel Lindberg

      Hi!

       

      We have customers using the MC40 and we need the ability to update our own application.

      This can be done through regular Android. But not with the MC40, due to that no Intent/Activity is responding to "android.intent.action.INSTALL_PACKAGE".

       

      Can this be solved?

       

      Best regards,

      Daniel

        • Re: MC40 install apk programmatically
          Billie Hecox

          Where will the APK reside when you try to install it? /sdcard?

            • Re: MC40 install apk programmatically
              Daniel Lindberg

              yes, the application downloads the apk and places it on the sdcard.

              Then the application tries to start the intent to install, this works great on standard andorid devices (Galaxy nexus, Motorola Razor), but it throws an exception when I try to do this with the MC40.

               

              The exception is as follows:

              android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSTALL_PACKAGE dat=file:///mnt/sdcard/Download/downloadedfilename.apk typ=application/vnd.android.package-archive }

                        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)

                        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)

                        at android.app.Activity.startActivityForResult(Activity.java:2827)

                        at android.app.Activity.startActivity(Activity.java:2933)

                        at com.cub.cublinkshopflow.MainActivity.installUpdate(MainActivity.java:337)

                        at com.cub.cublinkshopflow.MainActivity.access$4(MainActivity.java:319)

                        at com.cub.cublinkshopflow.MainActivity$4.onClick(MainActivity.java:244)

                        at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:159)

                        at android.os.Handler.dispatchMessage(Handler.java:99)

                        at android.os.Looper.loop(Looper.java:130)

                        at android.app.ActivityThread.main(ActivityThread.java:3683)

                        at java.lang.reflect.Method.invokeNative(Native Method)

                        at java.lang.reflect.Method.invoke(Method.java:507)

                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

                        at dalvik.system.NativeStart.main(Native Method)

            • Re: MC40 install apk programmatically
              Gary Crean

              You could run the command to install the APK manually.

               

              Example.

              Runtime.getRuntime().exec("pm install /sdcard/Download/downloadedfilename.apk ");

               

              But First you will need to remove the old package, This can be done by

               

              Runtime.getRuntime().exec("pm uninstall <Package Name> ");

               

              pm is an android application used to install packages,

               

              usage: pm [list|path|install|uninstall]
                     pm list packages [-f] [-d] [-e] [-u] [FILTER]
                     pm list permission-groups
                     pm list permissions [-g] [-f] [-d] [-u] [GROUP]
                     pm list instrumentation [-f] [TARGET-PACKAGE]
                     pm list features
                     pm list libraries
                     pm path PACKAGE
                     pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f] PATH
                     pm uninstall [-k] PACKAGE
                     pm clear PACKAGE
                     pm enable PACKAGE_OR_COMPONENT
                     pm disable PACKAGE_OR_COMPONENT
                     pm setInstallLocation [0/auto] [1/internal] [2/external]

              The list packages command prints all packages, optionally only
              those whose package name contains the text in FILTER.  Options:
                -f: see their associated file.
                -d: filter to include disbled packages.
                -e: filter to include enabled packages.
                -u: also include uninstalled packages.

              The list permission-groups command prints all known
              permission groups.

              The list permissions command prints all known
              permissions, optionally only those in GROUP.  Options:
                -g: organize by group.
                -f: print all information.
                -s: short summary.
                -d: only list dangerous permissions.
                -u: list only the permissions users will see.

              The list instrumentation command prints all instrumentations,
              or only those that target a specified package.  Options:
                -f: see their associated file.

              The list features command prints all features of the system.

              The path command prints the path to the .apk of a package.

              The install command installs a package to the system.  Options:
                -l: install the package with FORWARD_LOCK.
                -r: reinstall an exisiting app, keeping its data.
                -t: allow test .apks to be installed.
                -i: specify the installer package name.
                -s: install package on sdcard.
                -f: install package on internal flash.

              The uninstall command removes a package from the system. Options:
                -k: keep the data and cache directories around.
              after the package removal.

              The clear command deletes all data associated with a package.

              The enable and disable commands change the enabled state of
              a given package or component (written as "package/class").

              The getInstallLocation command gets the current install location
                0 [auto]: Let system decide the best location
                1 [internal]: Install on internal device storage
                2 [external]: Install on external media

              The setInstallLocation command changes the default install location
                0 [auto]: Let system decide the best location
                1 [internal]: Install on internal device storage
                2 [external]: Install on external media

              • Re: MC40 install apk programmatically
                Daniel Lindberg

                Hi!

                 

                I solved this with using

                new Intent(Intent.ACTION_VIEW); instead of using new Intent(Intent.ACTION_INSTALL_PACKAGE);