Intercepting ContentView
1 getWindow().getDecorView().setDrawingCacheEnabled(true); 2 try { 3 File myCaptureFile = new File("/mnt/sdcard/" 4 + System.currentTimeMillis() + ".jpg"); 5 BufferedOutputStream bos = new BufferedOutputStream( 6 new FileOutputStream(myCaptureFile)); 7 getWindow().getDecorView().getDrawingCache() 8 .compress(Bitmap.CompressFormat.JPEG, 80, bos); 9 bos.flush();10 bos.close();11 } catch (Exception e) {12 e.printStackTrace();13 }14 getWindow().getDecorView().setDrawingCacheEnabled(false);
Captures the specified View.
view.setDrawingCacheEnabled(true); try { File myCaptureFile = new File("/mnt/sdcard/" + System.currentTimeMillis() + ".jpg"); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(myCaptureFile)); view.getDrawingCache() .compress(Bitmap.CompressFormat.JPEG, 80, bos); bos.flush(); bos.close(); } catch (Exception e) { e.printStackTrace(); } view().setDrawingCacheEnabled(false);