转载请注明:http://www.cnblogs.com/frank-zouxu/p/4158159.html

今天,公司一个项目在进行中,遇到了屏幕取词的难题,对问题分步处理,首先得解决如何截取设备的屏幕,鉴于Android设备是基于Linux内核的,因此试着找到Android截图命令ScreenCap,在Android4.0的源码中找到:Android-屏幕设备截屏_第1张图片

其中ScreenCap是基于C++编写的,Screenshot是基于C编写的。这里使用ScreenCap.先进入手机的shell模式,进入命令行:adb shell screencap -h,获得打印信息

usage: screencap [-hp] [-d display-id] [FILENAME]  -h: this message  -p: save the file as a png.  -d: specify the display id to capture, default 0.If FILENAME ends with .png it will be saved as a png.If FILENAME is not given, the results will be printed to stdout.

  

然后我们使用Java代码完成屏幕截取:
            Process sh = Runtime.getRuntime().exec("su", null,null);                    OutputStream  os = sh.getOutputStream();                    os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));  
            //在运行时使用shell命令完成截屏操作 os.flush(); os.close(); sh.waitFor();
 

至此截屏文件(img.png)就被保存到了sd卡的根目录下了.时间仓促,整个过程叙述的不尽详细,只为记录今日所得。

  

更多相关文章

  1. android 操作命令
  2. Android编译系统详解(二)——命令执行流程
  3. Android屏幕坐标和LCD坐标的转换
  4. Android 取得手机屏幕大小
  5. Android自适应不同分辨率或不同屏幕大小的layout布局(横屏|竖屏)
  6. android屏幕适配建议

随机推荐

  1. 自定义View系列教程07--详解ViewGroup分
  2. android调用第三方软件打开下载的附件
  3. android桌面快捷方式添加数字角标的踩坑
  4. Cortex-A8和Android应用开发视频教程
  5. Android中如何像 360 一样优雅的杀死后台
  6. 系出名门 Android(安卓)系列文章索引
  7. Android(安卓)XML解析技术
  8. Android(安卓)Matrix矩阵详解
  9. Android(安卓)RoboGuice 使用指南(13):Ro
  10. eclipse导入的Android项目没有android.ja