最近写了一个截图的功能,activity启动之后,截屏。方法如下:
public class ScreenDebug {    public static void screenshot(final View v, final Activity activity) {        new Thread(new Runnable() {            @Override            public void run() {                try {                    Thread.sleep(3000);                } catch (InterruptedException e) {                    e.printStackTrace();                }                  activity.runOnUiThread(new Runnable() {                    @Override                    public void run() {                                                View view = v.getRootView();                        view.setDrawingCacheEnabled(true);                        view.buildDrawingCache();                        Bitmap bitmap = view.getDrawingCache();                        Toast.makeText(activity, "test", Toast.LENGTH_SHORT).show();                        if (bitmap != null) {                            System.out.println("bitmap got!");                            try {                                FileOutputStream out = new FileOutputStream(fname);                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);                                                                Log.d("test", "test");                            } catch (Exception e) {                                e.printStackTrace();                            }                          }                     }                  });            }          }).start();    }  

但是在运行之后,却报 "java.io.IOException: open failed: EROFS (Read-only file system), 最后在stackoverflow上找到答案,是因为现在有些手机不允许我们直接向sd card上写东西,因此做如下修改:
将String fname = "/sdcard/" + "screenshot.png";换成String fname = context.getFilesDir().getPath().toString() + "/screenshot.png";



更多相关文章

  1. Android实现屏幕截图并保存截图到指定文件
  2. Android 整屏截图与区域指定view或layout截屏并返回bitmap对象
  3. Android 截图程序实现 需要root权限
  4. Android屏幕截图研究
  5. Android平台截图
  6. adb 超快速截图bash脚本
  7. Android截屏截图的几种方法总结
  8. Android屏幕截图实现方式 系统截屏源码分析和三指截屏
  9. Android面试题集(含答案)

随机推荐

  1. AndroidStudio 备忘录之Spinner(下拉列表)
  2. android Shape实现边框圆角
  3. 【Android】 ListView之setEmptyView的问
  4. android 电池(二):android关机充电流程、充
  5. Android版本与Linux内核版本的关系
  6. android TabHost小结
  7. 关于声明文件中android:process属性说明
  8. android 获取MAC
  9. android 文件系统(
  10. Android系列教程之十:Intents and Intent