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

Android: Using the camera on certain devices causes the app to crash

    Details

      Description

      Call Ti.Media.showCamera and the camera opens up fine, takes the picture fine, then click ok, and the app crashes before reaching the success function.

      The picture does manage to get saved into the photo gallery.

      Sample code. Paste this into a new Android application.

      var win = Titanium.UI.createWindow();
      var imageView = Ti.UI.createImageView({height: Ti.UI.FILL, width: Ti.UI.Fill});
      win.add(imageView);
      	Titanium.Media.showCamera({
       
      		success:function(event)
      		{
      			Ti.API.info('#### Camera Success');
      			var cropRect = event.cropRect;
      			var image = event.media;
      			Ti.API.info(image.length);
      			var filename = Titanium.Filesystem.tempDirectory + "/"+ 'camera_photo' + new Date().getTime() + ".png";
      			Ti.API.info(filename);
      			var f = Titanium.Filesystem.getFile(filename);
      			Ti.API.info(f.nativePath);
      			if (f.exists()) {
      				Ti.API.info('The file exist , trying to delete it before using it :' + f.deleteFile());
      				f = Titanium.Filesystem.getFile(filename);
      			}
      			f.write(image);
      			alert('Camera Success! The file size is '+f.size+' bytes.\n Now trying to assign it to an image on the screen (this may fail for hi res images)')
      			imageView.image = f.nativePath;
      		},
      		cancel:function()
      		
      		{
      			Ti.API.info('#### Camera Cancel');
      		},
      		error:function(error)
      		{
      			// create alert
      			Ti.API.info('#### Camera Error');
      			var a = Titanium.UI.createAlertDialog({title:'Camera'});
       
      			// set message
      			if (error.code == Titanium.Media.NO_CAMERA)
      			{
      				a.setMessage('Device does not have video recording capabilities');
      			}
      			else
      			{
      				a.setMessage('Unexpected error: ' + error.code);
      			}
       
      			// show alert
      			a.show();
      		},
      		allowEditing:true
      	});
      win.open();
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                gmathews Gary Mathews
                Reporter:
                jmlewis1 Justin Lewis
                Reviewer:
                Andy Waldman
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

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

                    Git Source Code