Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 views
in Technique[技术] by (71.8m points)

installation - Install Android APK without prompt

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("
");
        } 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...