首页 > 其他 > 详细

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

时间:2017-02-08 13:28:38      阅读:196      评论:0      收藏:0      [点我收藏+]

通过这段时间对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) {
}
}

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

原文:http://www.cnblogs.com/hyylog/p/6377663.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!