private void screenshot() {
// 獲取屏幕
View dView = getWindow().getDecorView();
dView.setDrawingCacheEnabled(true);
dView.buildDrawingCache();
Bitmap bmp = dView.getDrawingCache();
if (bmp != null) {
try {
// 獲取內(nèi)置SD卡路徑
String sdCardPath = Environment.getExternalStorageDirectory().getPath(); // 圖片文件路徑
String filePath = sdCardPath + File.separator + "screenshot.png";
File file = new File(filePath);
FileOutputStream os = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 100, os);
os.flush();
os.close();
} catch (Exception e) {
}
}
}
使用方法:
screenshot();
說明:
本方法不能顯示狀態(tài)欄圖標(biāo),但是可以截圖狀態(tài)欄