截取当前活动
View view = getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
String fileBasePath;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { //大于等于10需要用系统提供的路径才能创建
fileBasePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + Environment.DIRECTORY_DOCUMENTS + "/aio/" + System.currentTimeMillis() + ".png";
}else{
fileBasePath = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/" + System.currentTimeMillis() + ".png";
}
File file = new File(fileBasePath);
file.getParentFile().mkdirs();
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
PlatformAPIUtils.uploadScreenSync(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}