Back to Demos List

GSW Browser Camera

This demonstration will show the ability to access the camera from within the browser.




About This Demo

This demo is using the cordova-plugin-camera plugin. For more information click here:


		var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};


GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized.

	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);

	GSW.Tests.cameraTakePicture = function() {
		navigator.camera.getPicture(GSW.Tests.onSuccess, GSW.Tests.onFail, {
			quality: 50,
			correctOrientation: true,
			destinationType: Camera.DestinationType.DATA_URL
		});
	}

	GSW.Tests.onSuccess = function(imageData) {
		console.log('onSuccess' + imageData);
		var image = document.getElementById('myImage');
		image.src = "data:image/jpeg;base64," + imageData;
	}

	GSW.Tests.onFail = function(message) {
		var para = document.getElementById('alert');
		let code = message;
		if(code === 20){
		    para.innerHTML = "Camera permissions are not enabled. Please enable camera permissions for GSW ConnectBot";
		}else{
			para.innerHTML = "Operation was not completed due to: " + message;				    
		}
	}
	document.getElementById("cameraTakePicture").addEventListener("click", GSW.Tests.cameraTakePicture);
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);