We are writing an Android app that shows ads on large screens. We have a backend where advertisers can select the ads, so they are updated almost instantly. Because there will be a lot of Android boxes running (plugged into HDMI screens), we should be able to update our software remotely.
This is the case:
Main app is running continuously (unless turned off) and the users never see anything Android related. We need an updater app that listens for updates and deletes the main apk, installs a new apk. While updating we will show an activity with "Updating, please wait", until the new main apk is installed and showing.
What we need:
We need help on how to implement the update mechanism without prompting the user on ROOTED DEVICE.
What we have:
The updater app is hooked into the boot received event, where a service starts (this service will listen for updates, which will be implemented by a colleague soon). The service can start an activity which will prompt the update info while updating.
In the updater activity
try {
Process proc = Runtime.getRuntime().exec(new String[]{"su", "pm install -r /mnt/sdcard/MYFOLDER/testAPK.apk"});
stringBuilder.append(String.valueOf(proc.waitFor()));
stringBuilder.append("\n");
} catch (Exception e) {
if (e instanceof IOException) {
Log.d(TAG, "IOException");
} else if (e instanceof InterruptedException) {
Log.d(TAG, "InterruptedException");
} else {
e.printStackTrace();
}
}
The StringBuilder prints 11, but does the same if I give random unexisting command..
In the Manifest
<!-- Permission to start UpdaterService on boot -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- Install/delete permissions, only granted to system apps -->
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
The Install packages and delete packages are useless if I don't install my app as system app, am I correct?
Long story short, no installation of my test APK, and I have no idea how to solve this. Any help would be appreciated!
There is no need to sign the app in order to install it on a phone. if you ever ran this app in the emulator and . apk file will automatically created in the \bin folder of you project folder. just copy this file/ send it by mail for him to install.
Just open your browser, find the APK file you want to download, and tap it – you should then be able to see it downloading on the top bar of your device. Once it's downloaded, open Downloads, tap on the APK file and tap Yes when prompted. The app will begin installing on your device.
You can simply use adb install command to install/update APK silently. Sample code is below
public static void InstallAPK(String filename){
File file = new File(filename);
if(file.exists()){
try {
String command;
command = "adb install -r " + filename;
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
proc.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
}
OR
Please check http://paulononaka.wordpress.com/2011/07/02/how-to-install-a-application-in-background-on-android/
public void InstallAPK(String filename){
Process process = Runtime.getRuntime().exec("su");
OutputStream out = process.getOutputStream();
String reinstall = "pm install -r " + filename + "\n";
String am = "am start -a android.intent.action.MAIN -n yourPackage/.MainActivity";
String cmd = reinstall + am + " &";
out.write(cmd.getBytes());
out.flush();
out.close();
process.waitFor();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With