无提示安装Android APK [英] Install Android APK without prompt

查看:210
本文介绍了无提示安装Android APK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在写一个Android应用程序,显示在大屏幕上的广告。 我们有一个后端,广告客户可以选择广告,所以他们几乎是即时更新。 因为会有很多的Andr​​oid箱运行(插入HDMI屏幕),我们应该能够远程更新我们的软件。

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.

这样的话:

主要应用在连续工作(除非关闭)和用户再也看不到任何东西的Andr​​oid相关。 我们需要一个更新的应用程序,侦听更新和删除主apk文件,安装新的APK。 虽然更新,我们将展示以更新中,请稍候,活动直到新的主APK安装和展示。

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.

我们需要的:

我们需要就如何落实该更新机制不提示用户的root权限的设备帮助。

We need help on how to implement the update mechanism without prompting the user on ROOTED DEVICE.

我们有:

该更新的应用程序挂到收到补的事件,其中一个服务的启动(此服务将监听的更新,这将是一个同事很快实现)。 该服务可以启动它会提示更新信息,而更新的活动。

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.

在更新活动

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

StringBuilder的打印11,但不相同的,如果我给随机unexisting命令。

The StringBuilder prints 11, but does the same if I give random unexisting command..

在清单

<!-- 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?

长话短说,无需安装我的测试APK,我不知道如何解决这个问题。 任何帮助将是AP preciated!

Long story short, no installation of my test APK, and I have no idea how to solve this. Any help would be appreciated!

推荐答案

您可以简单地使用ADB安装命令来安装/升级APK默默。样品code低于

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

请检查 <一href="http://paulononaka.word$p$pss.com/2011/07/02/how-to-install-a-application-in-background-on-android/">http://paulononaka.word$p$pss.com/2011/07/02/how-to-install-a-application-in-background-on-android/

这篇关于无提示安装Android APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆