【发布时间】:2014-02-13 17:04:44
【问题描述】:
我创建了一个在其他应用程序之上运行的服务。我希望该服务在用户看到它时截取整个屏幕的屏幕截图,而不管正在运行哪些应用程序。我可以让服务运行手机的屏幕截图功能并将其存储在特定位置吗?
【问题讨论】:
-
据我所知,这是做不到的。您只能截取您应用中的内容。
标签: android service screenshot
我创建了一个在其他应用程序之上运行的服务。我希望该服务在用户看到它时截取整个屏幕的屏幕截图,而不管正在运行哪些应用程序。我可以让服务运行手机的屏幕截图功能并将其存储在特定位置吗?
【问题讨论】:
标签: android service screenshot
我可以让服务运行手机的截图功能并将其存储在特定位置吗?
不,除非出于明显的隐私和安全原因,可能在 root 设备上除外。
【讨论】:
嗯,类似的问题在 stackoverflow 上很受欢迎:
How to programmatically take a screenshot in Android?
How to take screenshot programmatically?
how to take screenshot programmatically and save it on gallery?
尤其是这个很有用:
// 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();
}
Mualig,来自上述帖子之一。
【讨论】: