Created
October 27, 2011 19:24
-
-
Save rioleo/1320578 to your computer and use it in GitHub Desktop.
Titanium-Camera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
win.addEventListener('focus', function(e) { | |
Titanium.Media.showCamera({ | |
success:function(event) | |
{ | |
var cropRect = event.cropRect; | |
var image = event.media; | |
var data_to_send = { | |
"file": event.media, | |
"name": 'camera_photo.png' | |
}; | |
xhr = Titanium.Network.createHTTPClient(); | |
xhr.setRequestHeader("enctype", "multipart/form-data"); | |
xhr.setRequestHeader("Content-Type", "image/png"); | |
xhr.open("POST","http://www.send.to/me.php"); | |
xhr.setTimeout(10000); | |
xhr.send(data_to_send); | |
xhr.onload = function() { | |
textfield.value = this.responseText; | |
Ti.API.info(this.responseText); | |
Titanium.App.Properties.setString("askurl",this.responseText); | |
}; | |
}, | |
cancel:function() | |
{ | |
}, | |
error:function(error) | |
{ | |
// create alert | |
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 | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment