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

[TIMOB-24660] Android: Support loading downloaded images from gallery #9021

Merged
merged 4 commits into from May 9, 2017

Conversation

garymathews
Copy link
Contributor

@garymathews garymathews commented May 5, 2017

  • Implement support for content://com.android.providers.downloads.documents paths
TEST CASE
  • Download an image on device
  • Load the image from the app, it's filesize and filename should show correctly
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
var w = Ti.UI.createWindow({backgroundColor : 'grey'}),
    b = Titanium.UI.createButton({
        title : 'OPEN GALLERY',
        top : '10dp'
    }),
    iv = Ti.UI.createImageView({
        top : '65dp',
        width : '95%'
    }),
    sp = 'android.permission.READ_EXTERNAL_STORAGE';

function openGallery() {
    Ti.Media.openPhotoGallery({
        mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO],
        success: function(e) {
            iv.height = e.media.height * (iv.rect.width / e.media.width);
            iv.image = e.media;

            alert('filename: ' + e.media.file.name);
            alert('filesize: ' + e.media.length);
        },
        error: function(e) {
            Ti.API.error(JSON.stringify(e));
        }
    });
}

b.addEventListener('click', function(e) {
    if (Ti.Android.hasPermission(sp)) {
        openGallery();
    } else {
        Ti.Android.requestPermissions([sp], function(e) {
            if (e.success) {
                openGallery();
            } else {
                Ti.API.info('ERROR: ' + e.error);
            }
        });
    }
});

w.add(b);
w.add(iv);

w.open();

JIRA Ticket

@garymathews garymathews added this to the 6.2.0 milestone May 5, 2017
@garymathews garymathews requested a review from ypbnv May 5, 2017 12:41
Copy link
Contributor

@ypbnv ypbnv left a comment

Choose a reason for hiding this comment

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

Pass.

@ssjsamir ssjsamir self-requested a review May 9, 2017 16:24
Copy link
Contributor

@ssjsamir ssjsamir left a comment

Choose a reason for hiding this comment

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

FR Passed - Was able to view the correct file size and file name of a downloaded image from the downloads directory without an error.

Test Steps

  • Built the SDK form this PR
  • Copied the test case from the description and pasted it in to a titanium project
  • Ran the program
  • Pressed Open Gallery
  • Went to Downloads
  • Selected a recent image I downloaded
  • Was able to view filesize and filename without the application crashing

Environment

Appcelerator Command-Line Interface, version 6.2.0
Nexus 6P device (Android 7.1.2)
Operating System Name: Mac OS X El Capitan
Operating System Version: 10.11.6
Node.js Version: 4.6.0
npm: 4.2.8
Xcode: 8.2
Appcelerator Studio: 4.8.1.201612050850

@ssjsamir ssjsamir merged commit 11ce824 into tidev:master May 9, 2017
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

5 participants