Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14920] Android: startActivityForResult always returns RESULT_CANCELED in the callback

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.2.0
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterDavide Cassenti
AssigneeAshraf Abu
Created2013-08-20T14:31:46.000+0000
Updated2016-06-30T04:36:48.000+0000

Description

Description of the problem

When opening an intent to share data using startActivityForResult, the result e.resultCode is always set to RESULT_CANCELED

Test code

1) Use the following code to test 2) Share an image with an external app: if you share or cancel, the result is always CANCELED
var win = Ti.UI.createWindow({
    backgroundColor: 'black'
});
   
var btn = Ti.UI.createButton({
    title: 'Share'
});
btn.addEventListener('click', function(e) {
    var intent = Ti.Android.createIntent({
        type: "image/jpg",
        action: Ti.Android.ACTION_SEND
    });
    
    var image = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'image.jpg');
    Ti.API.info(image.nativePath);
	
	intent.putExtra(Ti.Android.EXTRA_SUBJECT, "Subject");
	intent.putExtra(Ti.Android.EXTRA_TITLE, "Title");
	intent.putExtra(Ti.Android.EXTRA_TEXT, "Text");
	intent.putExtraUri(Ti.Android.EXTRA_STREAM, image.nativePath);
	Ti.Android.currentActivity.startActivityForResult(Ti.Android.createIntentChooser(intent, "Share image"), function(e) {
		switch(e.resultCode) {
			case Ti.Android.RESULT_OK:
				alert("OK"); break;
			case Ti.Android.RESULT_CANCELED:
				alert("CANCELED"); break;
		}
	});
});

win.add(btn);
win.open();	

Comments

No comments

JSON Source