电视截屏并保存且修改权限

通过这段时间对Android电视的开发,做下总结:

请尊重原创,文章出处:http://www.cnblogs.com/hyylog/p/6377663.html

我这里是通过执行adb指令来进行截屏的:

Process process=Runtime. getRuntime().exec("screencap -p " + 路径+图片名称);

获取返回的图片流数据:

BufferedReader info=new BufferedReader(new InputStreamReader(process.getInputStream()));  

保存图片:

public void saveImage(Bitmap bitmap, String imagePath) throws Exception {
if (isFileExit(imagePath)) {
String filePath = imagePath;
FileOutputStream fos = null;
File file = new File(filePath, imageName);
try {
fos = new FileOutputStream(file);
if (null != fos) {
bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.flush();
fos.close();
}
filePermission(file.toString());
} catch (IOException e) {
if(file!=null&&file.exists()){
file.delete();
}
e.printStackTrace();
}

}

保存成功后修改图片读写权限:

public void filePermission(String url) {
try {
Process p;
int status = -1;
p = Runtime.getRuntime().exec("chmod 777 " + url);//chown shell:shell
status = p.waitFor();
if (status == 0) {
// chmod succeed
} else {
// chmod failed
}
} catch (Exception e) {
}
}

posted on 2017-02-08 12:31  韩仰阳  阅读(193)  评论(0编辑  收藏  举报