Video from android gallery.

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

I am trying to get video from android gallery by clicking on button and get reference from this link and implement it in to my code but I don't get any response and alert when gallery closed.

This code opens the gallery and take an input and close gallery properly, but when I select any file then activity function not run at all.

Even I don't getting OK alert when gallery close.

But yes when I removing code after alert('OK') then I gets an alert every time.

I did any mistake or something missing in this code?

var intent = Titanium.Android.createIntent({
            action : Ti.Android.ACTION_PICK,
            type : "video/*"
        });
 
 
Titanium.Android.currentActivity.startActivityForResult(intent, function(ex) {
    alert('OK');
// removing following code after this line give alert every time.
    if (ex.error) {
        Ti.UI.createNotification({
            duration : Ti.UI.NOTIFICATION_DURATION_LONG,
            message : 'Error: ' + ex.error
        }).show();
    } else {
        if (ex.resultCode === Titanium.Android.RESULT_OK) {
            var videoUri = ex.intent.data;
            var source = Ti.Filesystem.getFile(videoUri);
            var target = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + new Date().getTime() + "." + 'mp4');
            source.copy(target.nativePath);
    } else if (ex.resultCode === Titanium.Android.RESULT_CANCELED) {
        Ti.UI.createNotification({
            duration : Ti.UI.NOTIFICATION_DURATION_LONG,
            message : 'No Video loaded...'
        }).show();
    } else {
        Ti.UI.createNotification({
            duration : Ti.UI.NOTIFICATION_DURATION_LONG,
            message : 'Error? \n\nResult code: ' + ex.resultCode
        }).show();
            }
    }
});

1 Answer

startActivityForResult callback does not return a value ex.error your app is crashing there...

you probably want to check ex.resultCode

See documentation

— answered 9 months ago by Aaron Saunders
answer permalink
1 Comment
  • Thank you Aaron,

    I checked this code in simulator log on consol and also checked in DDMS for simulator and device. I did not found any error after intent start and gallery window closed.

    I removed all code and checked for a result code. It gives me result OK (-1) every time but I found that i did not get proper uri from intent.

    I am getting content://media/external/video/media/filenumber as uri.

    is there any way to get proper uri in this intent?

    — commented 9 months ago by Gaurang Chhatbar

Your Answer

Think you can help? Login to answer this question!