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-25849] Android: Always specify image mime-type #9918

Merged
merged 2 commits into from Mar 8, 2018

Conversation

garymathews
Copy link
Contributor

@garymathews garymathews commented Mar 8, 2018

  • Always specify image mime-type to obtain image information correctly
  • Remove annoying warning from TiBlob
NOTE: no tests as this test case requires user input
TEST CASE
var win = Ti.UI.createWindow(),
    btn = Ti.UI.createButton({
        title: 'OPEN GALLERY',
    });

btn.addEventListener('click', function(){
    Ti.Media.openPhotoGallery({
        mediaTypes: [ Titanium.Media.MEDIA_TYPE_PHOTO ],
        success: function (e) {
            var msg = 'media.width: ' + e.media.width
                + '\nmedia.height: ' + e.media.height
                + '\nmedia.length: ' + e.media.length
                + '\nmedia.mimeType: ' + e.media.mimeType
                + '\nmedia.nativePath: ' + e.media.nativePath;
            alert(msg);
        },
        error: function (e) {
            alert('error opening image: ' + e.error);
        }
    });
});

win.add(btn);
win.open();
  • Should see width height and mimeType populated after selecting an image

JIRA Ticket

@garymathews garymathews added this to the 7.2.0 milestone Mar 8, 2018
@garymathews garymathews changed the title [TIMOB-25849] Always specify image mime-type [TIMOB-25849] Android: Always specify image mime-type Mar 8, 2018
@build build added the android label Mar 8, 2018
}
return createDictForImage(imageData, null);
return createDictForImage(imageData, MIME_IMAGE);
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't hard code the mime-type like this. This is because the end-user is capable of selecting files others than images from the gallery. I've done it on my devices. In this case, a zero width/height makes sense.

Have a look at how my open PR handles it here...
https://github.com/appcelerator/titanium_mobile/pull/9223/files-diff

Here is a code snipped from my PR. It'll fetch the mime-type from the gallery app's content provider using the given content URI. I've tested this with photos, videos, and text files and it works. And I think it's okay to leave it null if the selected file is unknown since that won't happen for photos.

// Determine the mime type for the given file.
String mimeType = null;
boolean isPhoto = false;
try {
	mimeType = TiApplication.getInstance().getContentResolver().getType(Uri.parse(path));
	if ((mimeType != null) && mimeType.toLowerCase().startsWith("image")) {
		isPhoto = true;
	}
} catch (Exception ex) {
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Also note that the above will correctly set the mime-type for the selected image format such as "image/png", "image/jpeg", etc.

@garymathews
Copy link
Contributor Author

@jquick-axway Updated PR, we now attempt to obtain the mime-type from the content resolver. Also note that the user should not be able to select anything other than images due to this filter; although that may not be enforced correctly on all devices.

@build
Copy link
Contributor

build commented Mar 8, 2018

Messages
📖

💾 Here's the generated SDK zipfile.

Generated by 🚫 dangerJS

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

@lokeshchdhry
Copy link
Contributor

FR Passed.

Width & height of the selected photo is successfully retrieved.
If we try to select a video the behavior is not enforced on all devices as said by @garymathews above. On a Nexus 6P we are not allowed to select a video & on a Nexus 5 we can select a video but then its width & height is retrieved as zero.

Studio Ver: 5.0.0.201712081732
SDK Ver: 7.2.0 local build
OS Ver: 10.13.2
Xcode Ver: Xcode 9.2
Appc NPM: 4.2.12
Appc CLI: 7.0.2
Daemon Ver: 1.0.1
Ti CLI Ver: 5.0.14
Alloy Ver: 1.11.0
Node Ver: 8.9.1
NPM Ver: 5.5.1
Java Ver: 1.8.0_101
Devices: ⇨ google Nexus 6P --- Android 8.0.0
⇨ google Nexus 5 --- Android 6.0.1

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