The TwitPic.com website has a webservice API which will post a photo to a user's Twitter account along with a short message. You can use the download manager to upload a file. Even though it is called the download manager it has a method to upload files as well using HTTP POST.
this.controller.serviceRequest('palm://com.palm.downloadmanager/', {
method: 'upload',
parameters: {
'fileName': filename,
'fileLabel':'media',
'url': 'http://twitpic.com/api/uploadAndPost',
'contentType': 'image/jpg',
"postParameters": [
{"key":"username" , "data": username},
{"key":"password" , "data": password},
],
"subscribe": true
},
onSuccess : function (resp){
Mojo.Log.info('Success : ' + Object.toJSON(resp));
},
onFailure : function (e){
Mojo.Log.info('Failure : ' + Object.toJSON(e));
}.bind(this)
});
Use Object.toJSON(). It will turn any JavaScript object into a nicely formatted JSON string, which you can then print to the log.
Mojo.Log.info('Success : ' + Object.toJSON(someObject));
You must push the camera scene from your current scene. This will open the standard camera screen. When the user takes a picture or presses the cancel button it will return control to your scene, and you will get a call to the activate method.
//launch the camera view
this.controller.stageController.pushScene(
{
appId : 'com.palm.app.camera',
name: 'capture'
},
{
sublaunch : true,
filename : '/media/internal/testpicture.jpg'
}
);
//the activate function on your scene
activate: function(event) {
console.log("got an activate " + event);
if(event != undefined) {
//the camera returned
console.log("json = " + Object.toJSON(event));
console.log("filename of the photo = " + event.filename);
}
}
Use the Mojo.Environment.DeviceInfo
property.
Load the file using an AJAX request from a local URL, then parse it using the DOMParser class.
//create a setupRealData function that I can call from somewhere in my app
StartAssistant.prototype.setupRealData = function() {
var url = "content/content.xml";
var request = new Ajax.Request(url, {
method: 'get',
evalJSON: 'false', //to enforce parsing JSON if there is JSON response
onCreate: function(){console.info('******* onCreate happened')},
onLoading: function(){console.info('******* onLoading happened')},
onLoaded: function(){console.info('******* onLoaded happened')},
onSuccess: function(){console.info('******* onComplete happened')},
onComplete: this.gotResults.bind(this),
onFailure: this.failure.bind(this)
});
}
//this function will by called when AJAX request above returns successfully
StartAssistant.prototype.gotResults = function(event){
console.log("got the results");
var xmlstring = event.responseText;
// parse into a DOM document object
var xmlobject = (new DOMParser()).parseFromString(xmlstring, "text/xml");
// Use xpath to get the parts of the XML I care about
var nodes = document.evaluate("/content/section", xmlobject, null, XPathResult.ANY_TYPE, null);
var section = nodes.iterateNext();
while (section)
{
console.log("section = " + section);
section=nodes.iterateNext();
}
}
You can ask the email service to open a new card and have some fields filled in (to, subject, body, etc.)
this.controller.serviceRequest( 'palm://com.palm.applicationManager',
{
method: 'open',
parameters: {
id: 'com.palm.app.email',
params: {
summary: 'test subject', // subject line
recipients: [ // list of recipients
{
role:1, //1 == To, 2 == CC, 3 == BCC
value:'email@example.com',
}
],
text: "My message to you" // the email body
}
}
});