我希望UpdateService安装下载的应用更新,不用为用户提供通常的权限和更新提示 - 毕竟,我们控制硬件和软件。 要做到这一点,我想想我需要给我的应用程序超级用户权限(如果有其他方式,那么我的问题会变得完全不同)。 但我无法弄清楚如何做到这一点。
我已经了解了可以安装的超级用户应用程序 - 但这似乎是想要根据自己的手机用户的用户解决方案。或者是想要分发需要超级用户的应用程序的开发人员的解决方案,但他们无法控制用户将安装它的设备。
Android操作系统中是否有某个文件列出了应该有su的应用程序或用户?如果是这样,那没问题;我们控制着一切。
答案 0 :(得分:1)
首先我下载然后运行卸载并安装(系统已植根)
private void uninstall() {
try {
Process p = Runtime.getRuntime().exec("su");
InputStream es = p.getErrorStream();
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("pm uninstall com.example.app\n");
os.writeBytes("exit\n");
os.flush();
int read;
byte[] buffer = new byte[4096];
String output = new String();
while ((read = es.read(buffer)) > 0) {
output += new String(buffer, 0, read);
}
p.waitFor();
} catch (Exception e) {
}
}
private void install() {
try {
// Do the magic
Process p = Runtime.getRuntime().exec("su");
InputStream es = p.getErrorStream();
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("pm install /mnt/sdcard/exampple/app.apk\n");
os.writeBytes("exit\n");
os.flush();
int read;
byte[] buffer = new byte[4096];
String output = new String();
while ((read = es.read(buffer)) > 0) {
output += new String(buffer, 0, read);
}
p.waitFor();
} catch (IOException e) {
Log.d("catch silant", "1");
} catch (InterruptedException e) {
Log.d("catch silant", "2");
}
}
答案 1 :(得分:0)
我认为它可以帮助你,如果你成功请求,我现在也会尝试这样做,因为我很难做到这一点。