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
Your Answer
Think you can help? Login to answer this question!