[TIMOB-11183] Android: Intent com.android.camera.action.CROP not returning data
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-05-28T16:09:12.000+0000 |
Affected Version/s | Release 2.1.2, Release 2.1.3, Release 3.0.0 |
Fix Version/s | Release 3.1.0, 2013 Sprint 03 API, 2013 Sprint 03 |
Components | Android |
Labels | n/a |
Reporter | André Perazzi |
Assignee | Vivekr |
Created | 2012-09-20T09:51:48.000+0000 |
Updated | 2016-05-20T17:56:38.000+0000 |
Description
When starting an activity for an image crop intent's result, I cannot reach the data returned.
If i put the extra property ('return-data',true) into it, I can get a the text 'Android.Graphics.Bitmap@' after calling intent.getStringExtra("data"), but the data property of the returned intent is still null.
I'm attaching a code showing the problem.
It's almost impossible to let the user crop an image on Android, since the intent is not working and there are too many limitations when dealing with images on Android (such as pinch, scroll, etc).
var curWin = Ti.UI.createWindow({
backgroundColor : '#ffffff',
//navBarHidden:true, // IF THIS IS ENABLED THE startActivityForResult NOT WORK
exitOnClose : true
});
var myView = Ti.UI.createView();
var curBtn = Ti.UI.createButton({
color : '#000000',
title : 'Start Crop',
height : 'auto',
width : 'auto'
});
myView.add(curBtn);
curBtn.addEventListener('click', function(e) {
try {
Titanium.Media.openPhotoGallery({
success : function(event) {
var intent = Ti.Android.createIntent({
action : "com.android.camera.action.CROP",
data : event.media.nativePath,
type : 'image/*'
});
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 200);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
var activity = Ti.Android.currentActivity;
activity.startActivityForResult(intent, function(param) {
var iname = Ti.Android.EXTRA_STREAM;
if (param.resultCode == Ti.Android.RESULT_OK) {
alert('ok');
if (param.intent) {
// Daniel: The following calls return errors. Uncomment to clarify problem description.
//alert(JSON.stringify(param.intent.getStringExtra("data")));
//alert(JSON.stringify(param.intent.getBlobExtra("data")));
}
//vivekr : param.intent.getBlobExtra("data") works
var imageData = param.intent.getBlobExtra("data");
var image = Ti.UI.createImageView({
// Daniel: Problem description uses this, but the function doesn't exist:
// param.intent.getExtra("return-data")
// Andre: In my description, I meant that if I put the "intent.putExtra("return-data", true);"
// The result seems to come with data. If you remove this line, the result will be null
// vivekr: This doesnt work - image : param.intent.data
image : imageData,
width : 300,
height : 300,
top : 0,
left : 0,
backgroundColor : '#FFF'
});
var newWin = Ti.UI.createWindow({
backgroundColor : '#000',
//navBarHidden:true,
exitOnClose : true
});
newWin.add(image);
newWin.open();
}
});
},
error : function(error) {
},
cancel : function() {
}
});
} catch(e) {
}
});
curWin.add(myView);
curWin.open();
Attachments
File | Date | Size |
---|---|---|
Code.js | 2012-09-20T09:51:49.000+0000 | 2298 |
André: If I understand correctly, you seem to have two separate problems with this code: one that startActivityForResult is not fired when navBarHidden is set to true, and one that the data result is null. Is that correct? From the comment you added in the code, did using "param.intent.data" fix the null problem?
Yes for the 1st question, but the navBarHidden:true is a known issue. That's not a problem for me. My real problem is that the data result is null, no matter what I do. By adding "intent.putExtra("return-data", true);" the problem is not fixed, but I can get the result 'Android.Graphics.Bitmap@' by calling "param.intent.getStringExtra("data"))". Note that this data is a String, and not the image (object) itself. I can't find a way how to get the data object returned.
This bug makes almost impossible to crop an image on Androd, since Android has a lot of limitations such as pinch zoom, scrolling images in a scrollview (You can't put an image view in a scrollview when the image is actually bigger than the scrollview). Hope this bug gets fixed soon.
Working on it
Pull pending https://github.com/appcelerator/titanium_mobile/pull/3814
Image is getting cropped as expected. Verified on : SDK version: 3.1.0.v20130303194855 CLI version : 3.0.24 Android : 3.2
I used this code on Ti SDK 5.2.2.GA:
It seems to work for Android versions <6. But on Android 6 (API = 23) I get this error: