how can I make the Titanium.Media.openPhotoGallery work with android 4.1 sdk

You must Login before you can answer or comment on any questions.

Hi Bro,

I followed the book Appcelerator Titanium Smartphone App Development Cookbook instruction in Chapter5: Connecting your Apps with Social Media and E-mail on P.134, details as bellow:

buttonSelectImage.addEventListener('click',function(e){
//obtain an image from the gallery
Titanium.Media.openPhotoGallery({
success:function(event)
{
selectedImage = event.media;
// set image view
Ti.API.debug('Our type was: '+event.mediaType);
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
{
imageThumbnail.image = selectedImage;
}
},
cancel:function()
{
//user cancelled the action from within
//the photo gallery
}
});
});
win1.add(buttonSelectImage);
About this line : Ti.Media.MEDIA_TYPE_PHOTO, I look up on api doc. As you mention, I know that only works on iOS system. I’ve tried to find the solution on android system, but haven’t figured that out. Currently, I’m developing Android 4.1 System. Can you give me some advice to solve this problem?

Besides, Everytime when I click “Select Image Button” on this line I mentioned, my android will immediately crash without any error message. Hopefully, I can get the satisfy answers from you.

Thanks!

— asked 11 months ago by idar fan
1 Comment
  • Idar,

    I have been using this code snipped and it is working like a charm! I really don't understand why your code isn't working.

    //THUMBNAIL DA FOTO ENVIADA
    var thumb = Ti.UI.createImageView({
        top: '10%',
        zIndex: 2,
        backgroundColor:'#000',
        borderColor: '#000',
        borderRadius: 2,
        borderWidth: 3,
        visible: false
    });
    window.add(thumb);
     
    btn_openGallery.addEventListener('click', function(e){
        Ti.Media.openPhotoGallery({
            success:function(event) {                   
     
                //thumb---
                thumb.setImage(event.media);
                thumb.show();   
                //--------
            }
            cancel:function(){
                alert('Canceled!')
            }
        });
    });

    — commented 10 months ago by Douglas Alves

Your Answer

Think you can help? Login to answer this question!