Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Self updating app

TL:DR; version ;)

  • my app should run without user interaction (autostart etc works)

  • it should update itself (via apk) without any user interaction

  • rooted devices are possible

.

problem:

  • querying a newer apk from a server works
  • when starting the apk with a (view?) intent, the "install app" prompt pops and needs a user confirmation

How do I solve this without any user interaction?

http://code.google.com/p/auto-update-apk-client/ This seems to be a solution, but there must be better approach.

I already found this: Install Application programmatically on Android

but that doesn't solve my problem.

like image 805
Thkru Avatar asked Feb 20 '13 14:02

Thkru


2 Answers

Solved it! :D

It just works in rooted devices but works perfectly. Using the unix cmd "pm" (packageManager) allows you to install apks from sdcard, when executing it as root.

Hope this could help some people in the future.

public static void installNewApk() {         try         {             Runtime.getRuntime().exec(new String[] {"su", "-c", "pm install -r /mnt/internal/Download/fp.apk"});         }         catch (IOException e)         {             System.out.println(e.toString());             System.out.println("no root");         } } 

Required permissions:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
like image 176
Thkru Avatar answered Oct 09 '22 18:10

Thkru


My suggestion is to use plugin mechanism instad of updating the app. You can dynamically load classes from the Web and run them inside your app without any user interaction. There is a lot of resources spread across the Internet:

How to load a Java class dynamically on android/dalvik?

http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html

like image 39
Zielony Avatar answered Oct 09 '22 19:10

Zielony