I\'m developing an application that is installed on the system partition and I would like to know if it\'s possible to get a screenshot of the current foregroun
Months have passed since I asked this question but just now had the time to add this feature. The way to do this is simply by calling screencap -p
and then grabbing the file. Next is the code I used:
private class WorkerTask extends AsyncTask {
@Override
protected File doInBackground(String... params) {
File screenshotFile = new File(Environment.getExternalStorageDirectory().getPath(), SCREENSHOT_FILE_NAME);
try {
Process screencap = Runtime.getRuntime().exec("screencap -p " + screenshotFile.getAbsolutePath());
screencap.waitFor();
return screenshotFile;
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (InterruptedException ie) {
ie.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(File screenshot_file) {
// Do something with the file.
}
}
Remember to add the
permission to the manifest. Otherwise screenshot.png will be blank.
This is much simpler than what Goran stated and is what I finally used.
Note: It only worked for me when the app is installed on the system partition.