Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - How to take screenshot programmatically
    primarykey
    data
    text
    <p>I need to screenshots of Android device or emulator programmatically when my application is installed and running in the background for every 200 milliseconds and save the images in my computer. I have implemented this procedure using below code and works only when my application is in foreground. I want to take screenshots when my application is in background as well. Below is my code:</p> <pre><code>public static Bitmap takeScreenshot(Activity activity, int ResourceID) { Random r = new Random(); int iterator=r.nextInt(); String mPath = Environment.getExternalStorageDirectory().toString() + "/screenshots/"; View v1 = activity.getWindow().getDecorView().findViewById(ResourceID); v1.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); v1.layout(0, 0, v1.getMeasuredWidth(), v1.getMeasuredHeight()); v1.setDrawingCacheEnabled(true); final Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache()); Bitmap resultBitmap = Bitmap.createScaledBitmap(bitmap, 640, 480, false); v1.setDrawingCacheEnabled(false); File imageFile = new File(mPath); imageFile.mkdirs(); imageFile = new File(imageFile+"/"+iterator+"_screenshot.png"); try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); resultBitmap.compress(CompressFormat.PNG, 100, bos); byte[] bitmapdata = bos.toByteArray(); //write the bytes in file FileOutputStream fos = new FileOutputStream(imageFile); fos.write(bitmapdata); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return bitmap; } </code></pre> <p>How can I implement the functionality of Refresh and Save buttons of Screencapture in <code>Devices -&gt; DDMS</code> programmatically? Can I achieve that?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload