tv_screen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View dView = getWindow().getDecorView();
dView.setDrawingCacheEnabled(true);
dView.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(dView.getDrawingCache());
if (bitmap != null) {
img_screen.setImageBitmap(bitmap);
try {
// 获取内置SD卡路径
String sdCardPath = Environment.getExternalStorageDirectory().getPath();
// 图片文件路径
String filePath = sdCardPath + File.separator + "screenshot.png";
File file = new File(filePath);
FileOutputStream os = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
os.flush();
os.close();
//发广播告诉相册有图片需要更新,这样可以在图册下看到保存的图片了
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(file);
intent.setData(uri);
sendBroadcast(intent);
Log.d("a7888", "存储完成"+filePath+"sdCardPath"+sdCardPath);
} catch (Exception e) {
}
}
}
});