核心代码就是下面两行:
机器拥有root权限,升级时,有时正常升上去了,有时黑屏。
String cmd = "pm install -r " + filePath;
Runtime.getRuntime().exec(cmd);
机器拥有root权限,升级时,有时正常升上去了,有时黑屏。
String cmd = "pm install -r " + filePath;
Runtime.getRuntime().exec(cmd);
/**
* install slient
* @param filePath
* @return 0 file not exist , 1 success , -1 other exception error
*/
private int installSlient(String filePath) {
try {
if (filePath==null || filePath.length()==0) {
return 0;
}
File file = new File(filePath);
if (!file.exists() || !file.isFile() || file.length()<=0 ) {
return 0;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return -1;
}
try {
String cmd = "pm install -r " + filePath;
Runtime.getRuntime().exec(cmd);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return -2;
}
return 1;
}
/**
* install slient
* @param filePath
* @return 0 file not exist , 1 success , -1 other exception error
*/
private int installNoSilent(String filePath) {
try {
if (filePath==null || filePath.length()==0) {
return 0;
}
File file = new File(filePath);
if (!file.exists() || !file.isFile() || file.length()<=0 ) {
return 0;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return -1;
}
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.parse("file://" + filePath),
"application/vnd.android.package-archive");
this.context.startActivity(intent);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return -2;
}
return 1;
}