这是一个安全漏洞.你应该有一个root设备才能做到这一点.
// 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) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
尝试查看此代码以获取其他帮助:
附:可以使用DDMS从Android获取屏幕截图,但这是另一个故事.
P.P.S.如果你想在你下面的活动上透明地绘制你的启动器,你需要将像素格式设置为RGBA(仅处理OpenGL)并相应地渲染.您无需截取底层活动的屏幕截图即可.
root设备:在root设备上使用此代码:
process = Runtime.getRuntime().exec("su -c cat /dev/graphics/fb0");
InputStream is = process.getInputStream();