Android app unable to decode images for some users

78 Views Asked by At

I have an app that reads and enhances photos. Recently I (forced by Google) updated my app to use sdk 33. When I released it I began to get reports of errors. For these users it will not read any old photos, but can still use the camera to take a picture and use the photo in the app. It is able to save the photo. The users who reported problems (only 4 so far) have different types of phones: pixel 6 and 7, Samsung s21 Ultra. The error they get is "Unable to decode file".

I have tested it on my Pixel 5a, and various old Samsung phones. Also on some virtual phones in android studio chipmunk. It works fine for me. Does anyone know what is going on? Any advice how I can figure this out? Should I update to the latest android studio? Could that affect this?

New I Have found this on Google permissions: For a more privacy preserving experience for users, we’re introducing the Photo and Video Permissions policy to reduce the number of apps permitted to request broad photo/video permissions (READ_MEDIA_IMAGES and READ_MEDIA_VIDEO). Apps may only access photos and videos for purposes directly related to app functionality. Apps that have a one-time or infrequent need to access these files are requested to use a system picker, such as the Android photo picker. (effective August 31, 2024)

Here is the code

            options.inJustDecodeBounds = false;

            try {
                bmp = BitmapFactory.decodeFile(photoFilePath, options);
            } catch (Throwable t){
                bmp = null;
                showError("Out of memory error.  Reduce MPixel limit in settings.");
            }


            if (bmp == null) {
                showError("Unable to decode file." + photoFilePath);
                photoFilePath = null;
                return;
            }



    //this is how photoFilePath gets set
    private void onSelectFromGalleryResult(Intent data) {
        try {
            // When an Image is picked
            if (data != null && data.getData() != null) {
                // Get the Image from data

                Uri selectedImage = data.getData();

                String[] filePathColumn = {MediaStore.Images.Media.DATA};
                // Get the cursor
                Cursor cursor = getContentResolver().query(selectedImage,
                        filePathColumn, null, null, null);
                // Move to first row
                cursor.moveToFirst();
                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                photoFilePath = cursor.getString(columnIndex);
                cursor.close();

//                    showDiag("Image string " + photoFilePath);

//                    bmp = MediaStore.Images.Media.getBitmap(getContentResolver(), selectedImage);
            } else {
                showDiag("You haven't picked an image");
            }
        } catch (Exception e) {
            showError("Something went wrong");
            e.printStackTrace();

        }


0

There are 0 best solutions below