In simple words, I want to convert a viewgroup to a jpg image file. As Environment.getExternalStorageDirectory
is deprecated, I use this intent Intent.ACT
You need to use getContentResolver().openOutputStream
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (resultCode == RESULT_OK && requestCode == WRITE_REQUEST_CODE) {
FileOutputStream fileOutupStream = getContentResolver().openOutputStream(data.getData());
try {
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutupStream);
fileOutupStream.flush();
fileOutupStream.close();
Toast.makeText(this, "saved " + fileName, Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(this, "something went wrong" + e.getMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
}