I've created a Service which runs on top of other apps. I want the service to take a screenshot of the entire screen as the user sees it regardless of what apps are running. Can I have the service run the screenshot function of the phone and store it in a specific location?
Can I have the service run the screenshot function of the phone and store it in a specific location?
No, except perhaps on rooted devices, for obvious privacy and security reasons.
well, similar questions have been really popular on stackoverflow:
How to programmatically take a screenshot in Android?
How to take screenshot programmatically?
how to take screenshot programmatically and save it on gallery?
Especially, this one is usefull:
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" +
ACCUWX.IMAGE_APPEND;
// create bitmap screen capture
Bitmap bitmap;
View v1 = mCurrentUrlMask.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
OutputStream fout = null;
imageFile = new File(mPath);
try {
fout = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
fout.flush();
fout.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
by Mualig, from one of the posts above.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.