80,349
社区成员
发帖
与我相关
我的任务
分享
/**
* 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;
}
/**
* install apk
*/
public void installApk() {
//new installApkThread().start();
if ((downLoadStorageFileDir!=null) && (apkName!=null)) {
String filePath = downLoadStorageFileDir + File.separatorChar + apkName;
AvcLog.printW(TAG, "start install apk : " + filePath);
int iRet = installSlientEx(filePath);
AvcLog.printW(TAG, "finish install apk, reboot : the result is " + iRet);
AvcApp.the().getCore().onReboot();
} else {
AvcLog.printW(TAG, "installApkThread : path is null");
}
}
/**
* install slient
* @param filePath
* @return 0 file not exist , 1 success , -1 other exception error
*/
private int installSlientEx(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;
}
Process proc = null;
try {
String cmd = "pm install -r " + filePath;
Runtime runtime = Runtime.getRuntime();
AvcLog.printW(TAG, "post cmd : " + filePath);
proc = runtime.exec(cmd);
Thread.sleep(3000);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return -2;
} finally {
if (proc != null) {
proc.destroy();
}
}
return 1;
}