Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-11183

Android: Intent com.android.camera.action.CROP not returning data

    Details

    • Type: Bug
    • Status: Closed
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: Release 2.1.2, Release 2.1.3, Release 3.0.0
    • Component/s: Android
    • Labels:
      None
    • Environment:

      OS X 10.8.2, Titanium Studio 2.1.2, SDK 2.1.1.GA

      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

          Activity

            People

            • Assignee:
              vivekr Vivekr
              Reporter:
              andreperazzi André Perazzi
              Reviewer:
              Allen Yeung
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-14468
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Integration