我们正在编写一个可在大屏幕上显示广告的Android应用。我们有一个后端,供广告商选择广告,因此几乎可以立即对其进行更新。由于将运行许多Android机器(插入HDMI屏幕),因此我们应该能够远程更新我们的软件。
就是这种情况:
主应用程序持续运行(除非关闭),并且用户永远不会看到与Android相关的任何内容。我们需要一个更新程序应用程序,该应用程序侦听更新并删除主apk,并安装新的apk。更新时,我们将显示“正在更新,请稍候”的活动,直到安装并显示新的主要apk。
我们需要的:
我们需要有关如何实施更新机制的帮助,而无需在ROOTED DEVICE上提示用户。
我们有什么:
updater应用程序被挂接到启动已接收事件中,在该事件中服务启动(此服务将监听更新,该更新将很快由同事实施)。该服务可以启动一个活动,该活动将在更新时提示更新信息。
在更新程序活动中
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,但如果我给出随机不存在的命令,也会执行相同的操作。
在清单中
<!-- 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" />
如果我不将应用程序安装为系统应用程序,则安装软件包和删除软件包无用,对吗?
长话短说,我没有安装测试APK,而且我也不知道如何解决这个问题。任何帮助,将不胜感激!
您可以简单地使用adb install命令以静默方式安装/更新APK。示例代码如下
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();
}
}
}
或者
请检查http://paulononaka.wordpress.com/2011/07/02/how-to-install-a-application-in-background-on-android/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句