[英]Install Android APK without prompt
We are writing an Android app that shows ads on large screens.我们正在编写一个在大屏幕上显示广告的 Android 应用程序。 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.
因为会有很多 Android 盒子在运行(插入 HDMI 屏幕),所以我们应该能够远程更新我们的软件。
This is the case:情况是这样的:
Main app is running continuously (unless turned off) and the users never see anything Android related.主应用程序持续运行(除非关闭),用户永远不会看到任何与 Android 相关的内容。 We need an updater app that listens for updates and deletes the main apk, installs a new apk.
我们需要一个更新程序应用程序来监听更新并删除主 apk,安装一个新的 apk。 While updating we will show an activity with "Updating, please wait", until the new main apk is installed and showing.
在更新时,我们将显示一个带有“正在更新,请稍候”的活动,直到安装并显示新的主 apk。
What we need:我们需要的:
We need help on how to implement the update mechanism without prompting the user on ROOTED DEVICE.我们需要关于如何实现更新机制而不在 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.. StringBuilder 打印 11,但如果我给出随机不存在的命令,它也会打印。
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.长话短说,没有安装我的测试 APK,我不知道如何解决这个问题。 Any help would be appreciated!
任何帮助,将不胜感激!
You can simply use adb install command to install/update APK silently.您可以简单地使用 adb install 命令静默安装/更新 APK。 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/请检查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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.