Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9837734b authored by Mike Lockwood's avatar Mike Lockwood
Browse files

GlobalScreenshot: Set image file size in media database when taking screenshots



Otherwise the value would be left at zero since we are inserting
the database record before writing the file

Bug: 5064246

Change-Id: I54be6ff14a7f170994aaf586aaddb06c5b746e89
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent c6eaa713
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.graphics.Bitmap;
@@ -99,6 +100,7 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi

            // Save the screenshot to the MediaStore
            ContentValues values = new ContentValues();
            ContentResolver resolver = context.getContentResolver();
            values.put(MediaStore.Images.ImageColumns.DATA, imageFilePath);
            values.put(MediaStore.Images.ImageColumns.TITLE, imageFileName);
            values.put(MediaStore.Images.ImageColumns.DISPLAY_NAME, imageFileName);
@@ -106,14 +108,18 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
            values.put(MediaStore.Images.ImageColumns.DATE_ADDED, currentTime);
            values.put(MediaStore.Images.ImageColumns.DATE_MODIFIED, currentTime);
            values.put(MediaStore.Images.ImageColumns.MIME_TYPE, "image/png");
            Uri uri = context.getContentResolver().insert(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

            OutputStream out = context.getContentResolver().openOutputStream(uri);
            OutputStream out = resolver.openOutputStream(uri);
            image.compress(Bitmap.CompressFormat.PNG, 100, out);
            out.flush();
            out.close();

            // update file size in the database
            values.clear();
            values.put(MediaStore.Images.ImageColumns.SIZE, new File(imageFilePath).length());
            resolver.update(uri, values, null, null);

            params[0].result = 0;
        } catch (Exception e) {
            // IOException/UnsupportedOperationException may be thrown if external storage is not