Androidスクリーンショットをローカルに保存
次の方法を使用します.
権限を追加するのを忘れないで~~~、抽出するのがおっくうで、すべてプラスしましょう
拒否された場合は、次の文書でユーザーに権限を開くよう求めます.
https://blog.csdn.net/wuqingsen1/article/details/84836679
//
public void screenShort() {
View dView = getWindow().getDecorView();
dView.setDrawingCacheEnabled(true);
dView.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(dView.getDrawingCache());
if (bitmap != null) {
try {
saveBitmap(bitmap);
} catch (Exception e) {
}
}
}
//
private void saveBitmap(Bitmap bmp) throws IOException {
File childFolder = Environment.getExternalStoragePublicDirectory(Environment
.DIRECTORY_PICTURES);
File imageFile = new File(childFolder.getAbsolutePath() + "/" + System.currentTimeMillis
() + ".jpg");
OutputStream fOut = new FileOutputStream(imageFile);
bmp.compress(Bitmap.CompressFormat.JPEG, 60, fOut);// bg
fOut.flush();
fOut.close(); // do not forget to close the stream
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile
(imageFile)));
ToastUtils.showShort(getString(R.string.success));
}
権限を追加するのを忘れないで~~~、抽出するのがおっくうで、すべてプラスしましょう
拒否された場合は、次の文書でユーザーに権限を開くよう求めます.
https://blog.csdn.net/wuqingsen1/article/details/84836679