【发布时间】:2016-06-26 21:23:06
【问题描述】:
我已经尝试过 StackOverFlow 和其他网站中给出的许多方法,但它并没有真正奏效。
我的问题是我有这个需要更新的应用程序,更新后它应该会自动重新打开相同的应用程序(更新)。
这是我的代码:
private synchronized void runRootUpdate() {
// Install Updated APK
String command = "pm install -r " + downloadPath + apkFile;
Process proc = Runtime.getRuntime().exec(new String[] {"su", "-c", command});
int test = proc.waitFor(); // Error is here.
if (proc.exitValue() == 0) {
// Successfully installed updated app
doRestart()
} else {
// Fail
throw new Exception("Root installation failed");
}
}
private void doRestart() {
Intent mStartActivity = new Intent(context, MainActivity.class);
int mPendingIntentId = 123456;
PendingIntent mPendingIntent = PendingIntent.getActivity(context, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
System.exit(0);
}
看看我的“错误就在这里”。我的旧应用程序将安装一个新的更新应用程序并杀死自己,因此没有 proc.waitFor() 并最终回到主屏幕但正在安装新的更新应用程序。但是,我需要它来重新启动它。有什么办法可以做到吗?
【问题讨论】:
-
你现在有什么解决办法吗?
-
您打算如何更新它?当你的应用程序在前台运行时它是否打开?
标签: android