Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17632] Android: takePicture(): Camera preview is not open, unable to take photo

GitHub Issuen/a
TypeBug
PriorityNone
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.3.0
Fix Version/sn/a
ComponentsAndroid
LabelsTCSupport, openCamera, takePicture
ReporterMateusz Golewski
AssigneeUnknown
Created2014-08-27T11:14:33.000+0000
Updated2018-02-28T20:04:07.000+0000

Description

Problem Description

After I openCamera(), I try to takePicture() and following error appears in console:
[ERROR] :  TiMedia: (KrollRuntimeThread) [1110,1110] Camera preview is not open, unable to take photo
But preview is opening and working well.. Hello, We have tested this issue. Ti.Media.takePicture() only works on the overlay. But when we take the photo it continuously capture the photo on the galaxy s3 real device. It's a valid bug.

Steps to Reproduce

1. Create classic project. 2. Paste this file in app.js file.
var win1 = Titanium.UI.createWindow({
	backgroundColor : '#fff',
	layout : 'vertical'
});

var frmcamera = Ti.UI.createButton({
	backgroundColor : '#ff0000',
	title : 'Open Camera',
	color : '#fff',
	width : Ti.UI.SIZE,
	height : Ti.UI.SIZE,
	top : 10

});

frmcamera.addEventListener('click', function() {
	fireUpTheCamera();

});

win1.add(frmcamera);

var overlay = Ti.UI.createView({
	width : 80,
	height : 80,
	bottom : 20
});

// Create a Button.
var btn = Ti.UI.createButton({
	title : 'Take',
	height : 60,
	width : 60

});

btn.addEventListener('click', function() {
	Ti.Media.takePicture();
});
overlay.add(btn);

function fireUpTheCamera() {
	Titanium.Media.showCamera({

		success : function() {
			console.log('taken');
		},
		saveToPhotoGallery : true,
		autohide : false,
		overlay : overlay,
		mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO]
	});

}

win1.open();

3. Run it in device attached to Android Monitor

Comments

  1. Mateusz Golewski 2014-08-27

    Regarding to the source: https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java#L420 and https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java#L293 takePicture() works only if overlay is set.

JSON Source