Android, Why empty the `MediaStore.Images.Media.DESCRIPTION` 's field of value?

41 Views Asked by At

The java code is as follows:

ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "lol");
values.put(MediaStore.Images.Media.DISPLAY_NAME, "lol.jpg");
values.put(MediaStore.Images.Media.DESCRIPTION, "this is a lol image");
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
Log.i(TAG, "onRequestPermissionsResult, values: " + values);
// insert data, return Uri
Uri uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
// load app image1.jpg image
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.lol);
if (uri == null) return;
Log.i(TAG, "onRequestPermissionsResult, image's Path: " + uri.getPath());
try (
    // get Uri os
    OutputStream os = getContentResolver().openOutputStream(uri) // This line of code caused it
){
    // save image
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
} catch (IOException e) {
    Log.e(TAG, "onRequestPermissionsResult, ", e);
    throw new RuntimeException(e);
}
Toast.makeText(MainActivity.this, "success!", Toast.LENGTH_SHORT).show();

Android, Why empty the MediaStore.Images.Media.DESCRIPTION's field of value?

This line of code caused it:

OutputStream os = getContentResolver().openOutputStream(uri)

Is this a bug in the Android system or the cause of my code error?

To display MediaStore.Images.Media.DESCRIPTION.

Not empty the MediaStore.Images.Media.DESCRIPTION's field of value;

0

There are 0 best solutions below