/**
* 获取截图
* @param path 保存的文件地址 之后在此地址找图片即可
* @param name 保存的文件名
* @param context
*/
public void TakeScreenshot(String path, String name, Context context) {
this.executer("screencap -p " + path + name);
}
/**
* 执行命令
* @param command 执行命令
* @return
*/
private String executer(String command) {
StringBuffer output = new StringBuffer();
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command + "\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while((line = reader.readLine()) != null) {
output.append(line + "\n");
}
} catch (Exception var15) {
var15.printStackTrace();
} finally {
try {
if (os != null) {
os.close();
}
if (process != null) {
process.destroy();
}
} catch (Exception var14) {
var14.printStackTrace();
}
}
String response = output.toString().trim();
return response;
}
Android调用命令执行截图并保存到输入的地址
最新推荐文章于 2024-07-14 21:53:39 发布