Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): saveToPhotoGallery function targeting Android 10 #11490

Merged
merged 7 commits into from Mar 23, 2020

Conversation

garymathews
Copy link
Contributor

@garymathews garymathews commented Feb 21, 2020

  • saveToPhotoGallery should function correctly when targeting Android 10+
  • File. createTempFile causes issues on Android 10+ when attempting to create a file on external storage
  • It is not necessary to immediately create a file, only the File instance is necessary, preventing a permissions error
  • Utilize ContentResolver and MediaStore to access external media files
NOTES
  • It was not necessary to support scoped storage access
TEST CASE

(Test the below on Android 10.0 and Android 4.4.)

const win = Ti.UI.createWindow();

function takePicture() {
    Ti.Media.showCamera( {
        success(e) {
            console.log('showCamera: success!');
            win.backgroundColor = 'orange';

            Ti.Media.saveToPhotoGallery(e.media, {
                success(e) {
                    console.log('saveToPhotoGallery: success!');
                    win.backgroundColor = 'green';
                },
                error(e) {
                    console.error(e);
                    win.backgroundColor = 'red';
                }
            });
        },
        cancel(e) {
            console.warn(e);
        },
        error(e) {
            console.error(e);
            win.backgroundColor = 'red';
        },
        saveToPhotoGallery: true,
        mediaTypes: [ Ti.Media.MEDIA_TYPE_PHOTO ]
    });
}

win.addEventListener('click', _ => {
    if (Ti.Media.hasCameraPermissions()) {
        takePicture();
        return;
    }
    Ti.Media.requestCameraPermissions(e => {
        if (!e.success) {
            console.warn('Failed to get permissions.');
            win.backgroundColor = 'red';
            return;
        }
        takePicture();
    });
});
 
win.open();
  • Should not see Failed to create file: Permission denied
  • Both images and videos should be present in gallery

JIRA Ticket

@build
Copy link
Contributor

build commented Feb 21, 2020

Messages
📖 👍 Hey!, You deleted more code than you added. That's awesome!
📖

💾 Here's the generated SDK zipfile.

📖 ✊ The commits in this PR match our conventions! Feel free to Rebase and Merge this PR when ready.
📖

✅ All tests are passing
Nice one! All 6626 tests are passing.
(There are 699 skipped tests not included in that total)

Generated by 🚫 dangerJS against 6da1237

@garymathews
Copy link
Contributor Author

@jquick-axway Ready for review. I also gave MediaModule.java a quick refactor, removing redundant/poor code.

Copy link
Contributor

@jquick-axway jquick-axway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: Pass

@ssaddique
Copy link
Contributor

FR: Pass
See JIRA ticket for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants