静默安装,不稳定,是为何?

中才德创 中才德创 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
核心代码就是下面两行:
机器拥有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;
}
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
中才德创
Android 80,488 成员 91,371 内容