android如何实现静默安装哦
答案:3 悬赏:10 手机版
解决时间 2021-03-02 07:57
- 提问者网友:最美的风景
- 2021-03-01 09:07
android如何实现静默安装哦
最佳答案
- 五星知识达人网友:慢性怪人
- 2021-03-01 10:31
原理
静默安装、卸载的原理就是利用pm install命令来安装apk,pm uninstall 来卸载apk.
智能安装是利用android系统提供的无障碍服务AccessibilityService,来模拟用户点击,从而自动安装.
//静默安装
private void installSlient() {
String cmd = "pm install -r /mnt/sdcard/test.apk";
Process process = null;
DataOutputStream os = null;
BufferedReader successResult = null;
BufferedReader errorResult = null;
StringBuilder successMsg = null;
StringBuilder errorMsg = null;
try {
//静默安装需要root权限
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.write(cmd.getBytes());
os.writeBytes("
");
os.writeBytes("exit
");
os.flush();
//执行命令
process.waitFor();
//获取返回结果
successMsg = new StringBuilder();
errorMsg = new StringBuilder();
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) {
e.printStackTrace();
} finally {
try {
if (os != null) {
os.close();
}
if (process != null) {
process.destroy();
}
if (successResult != null) {
successResult.close();
}
if (errorResult != null) {
errorResult.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
//显示结果
tvTest.setText("成功消息:" + successMsg.toString() + "
" + "错误消息: " + errorMsg.toString());
}
静默安装、卸载的原理就是利用pm install命令来安装apk,pm uninstall 来卸载apk.
智能安装是利用android系统提供的无障碍服务AccessibilityService,来模拟用户点击,从而自动安装.
//静默安装
private void installSlient() {
String cmd = "pm install -r /mnt/sdcard/test.apk";
Process process = null;
DataOutputStream os = null;
BufferedReader successResult = null;
BufferedReader errorResult = null;
StringBuilder successMsg = null;
StringBuilder errorMsg = null;
try {
//静默安装需要root权限
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.write(cmd.getBytes());
os.writeBytes("
");
os.writeBytes("exit
");
os.flush();
//执行命令
process.waitFor();
//获取返回结果
successMsg = new StringBuilder();
errorMsg = new StringBuilder();
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) {
e.printStackTrace();
} finally {
try {
if (os != null) {
os.close();
}
if (process != null) {
process.destroy();
}
if (successResult != null) {
successResult.close();
}
if (errorResult != null) {
errorResult.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
//显示结果
tvTest.setText("成功消息:" + successMsg.toString() + "
" + "错误消息: " + errorMsg.toString());
}
全部回答
- 1楼网友:冷風如刀
- 2021-03-01 12:08
静默安装是指应用商店那些应用自动安装吗
- 2楼网友:醉吻情书
- 2021-03-01 11:30
要么root,要么给应用添加辅助功能
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯