Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15110] Android: Camera photos are not saving in Photo Gallery

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2013-09-30T13:07:19.000+0000
Affected Version/sRelease 3.1.0, Release 3.1.1, Release 3.1.2
Fix Version/s2013 Sprint 21, 2013 Sprint 21 API
ComponentsAndroid
Labelsandroid, ipass1
ReporterMotiur Rahman
AssigneeSunila
Created2013-09-10T07:57:06.000+0000
Updated2017-03-28T20:23:49.000+0000

Description

Camera photo's is not saving in a photo gallery. This following code is working in 3.0.2 version but it's not working in later version for android platform.

var win = Ti.UI.createWindow({
	backgroundColor : '#fff'
});

function fireUpTheCamera() {
	Titanium.Media.showCamera({
		saveToPhotoGallery : true,
		allowEditing : false,
		autohide : false, //Important!
		mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO],
		success : function(event) {
			
			Ti.API.debug('Our type was: ' + event.mediaType);
			if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
				var imageView = Ti.UI.createImageView({
					width : win.width,
					height : win.height,
					image : event.media
				});
				win.add(imageView);
				
			} else {
				alert("got the wrong type back =" + event.mediaType);
			}
		},
		cancel : function() {
			// called when user cancels taking a picture
		},
		error : function(error) {
			// called when there's an error
			var a = Titanium.UI.createAlertDialog({
				title : 'Camera'
			});
			if (error.code == Titanium.Media.NO_CAMERA) {
				a.setMessage('Please run this test on device');
			} else {
				a.setMessage('Unexpected error: ' + error.code);
			}
			a.show();
		},

		
	});
}

fireUpTheCamera();
win.open();

Attachments

FileDateSize
log.txt2013-09-16T11:12:09.000+0000636

Comments

  1. Motiur Rahman 2013-09-11

    Hi Ingo Muschenetz, Please check this code and try to fix this bug urgently cause it's important for our project. Thanks
  2. Sunila 2013-09-30

    Since the 'useLegacyWindow' is false by default, the window that is created has it's own activity. Here the fireUpTheCamera is called before the window is created and the activity that is used to handle the callback after the photo is taken is associated with the main activity and not window activity. Only after the window is closed, the main activity resumes and callback is called to save the file. The code will work if the 'useLegacyWindow' is set to true or the 'showcamera' is called after the window is opened. Something like calling 'fireUpTheCamera' from a button click in the window.
  3. Sunila 2013-09-30

    Here is the code that works var win = Ti.UI.createWindow(); function fireUpTheCamera() { Titanium.Media.showCamera({ saveToPhotoGallery : true, allowEditing : false, autohide : false, //Important! mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO], success : function(event) { Ti.API.debug('Our type was: ' + event.mediaType); if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) { var imageView = Ti.UI.createImageView({ width : win.width, height : win.height, image : event.media }); win.add(imageView); } else { alert("got the wrong type back =" + event.mediaType); } }, cancel : function() { // called when user cancels taking a picture }, error : function(error) { // called when there's an error var a = Titanium.UI.createAlertDialog({ title : 'Camera' }); if (error.code == Titanium.Media.NO_CAMERA) { a.setMessage('Please run this test on device'); } else { a.setMessage('Unexpected error: ' + error.code); } a.show(); }, }); } win.open(); var btnShowCamera = Ti.UI.createButton({ title : 'Take picture', width : 150, height : 70, top : 50 }); win.add(btnShowCamera); btnShowCamera.addEventListener('click', function(e) { fireUpTheCamera(); });
  4. Sunila 2013-10-02

    I tried this on Google Nexus with Android 4.3 Google Nexus S with Android 4.1.2 Motorola zoom tablet with Android 4.0.4 and is working fine with the new code and I am able to reproduce the issue with the old code. I don't have a 2.3.4 version to test this.
  5. Eric Merriman 2017-03-28

    Closing

JSON Source