|
@@ -10,7 +10,9 @@ import android.os.IBinder;
|
|
|
import com.wdkl.callingbed2.util.AutoRebootUtil;
|
|
|
import com.wdkl.callingbed2.util.LogUtil;
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
|
+import java.io.InputStreamReader;
|
|
|
import java.lang.reflect.Method;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -63,6 +65,61 @@ public class SilentUpdateUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void updateApk2(Context context) {
|
|
|
+ if (checkIsExitAPK(context)) {
|
|
|
+ LogUtil.d("apk", "文件存在");
|
|
|
+ } else {
|
|
|
+ LogUtil.d("apk", "文件不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String path = FILE_APK_PATH + "/" + FILE_APK_NAME;
|
|
|
+ if (installApp(context.getPackageName(), path)) {
|
|
|
+ doRestart(context);
|
|
|
+ } else {
|
|
|
+ LogUtil.d("apk", "安装失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean installApp(String packageName, String apkPath) {
|
|
|
+ Process process = null;
|
|
|
+ BufferedReader successResult = null;
|
|
|
+ BufferedReader errorResult = null;
|
|
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
+ StringBuilder errorMsg = new StringBuilder();
|
|
|
+ try {
|
|
|
+ process = new ProcessBuilder("pm", "install", "-i", packageName, "-r", apkPath).start();
|
|
|
+ successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
|
+ errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
|
|
+ String s;
|
|
|
+ while ((s = successResult.readLine()) != null) {
|
|
|
+ successMsg.append(s);
|
|
|
+ }
|
|
|
+ while ((s = errorResult.readLine()) != null) {
|
|
|
+ errorMsg.append(s);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (successResult != null) {
|
|
|
+ successResult.close();
|
|
|
+ }
|
|
|
+ if (errorResult != null) {
|
|
|
+ errorResult.close();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ if (process != null) {
|
|
|
+ process.destroy();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LogUtil.e("result", "" + errorMsg.toString());
|
|
|
+ //如果含有“success”认为安装成功
|
|
|
+ return successMsg.toString().equalsIgnoreCase("success");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 检查是否存在apk
|
|
|
*/
|