Table Of Contents

How do I upload an image to Twitter?

The 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,
        'url': '',
        'contentType': 'image/jpg',
        "postParameters": [
            {"key":"username" , "data": username},
            {"key":"password" , "data": password},
        "subscribe": true 
    onSuccess : function (resp){'Success : ' + Object.toJSON(resp));
    onFailure : function (e){'Failure : ' + Object.toJSON(e));

Learn More

How do I print out an object for debugging?

Use Object.toJSON(). It will turn any JavaScript object into a nicely formatted JSON string, which you can then print to the log.'Success : ' + Object.toJSON(someObject));

Learn More

How do I take a picture using the camera?

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	
        appId : '', 
        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);

Learn More

How do I tell if my app is running on a Pre or a Pixi?

Use the Mojo.Environment.DeviceInfo property.

Learn More

How do I load and parse a local XML file?

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(){'******* onCreate happened')},
        onLoading: function(){'******* onLoading happened')},
        onLoaded: function(){'******* onLoaded happened')},
        onSuccess: function(){'******* 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);

Learn More

How do I send an email?

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: '',
        params: {
            summary: 'test subject', // subject line
            recipients: [ // list of recipients
                role:1, //1 == To, 2 == CC, 3 == BCC
            text: "My message to you" // the email body

Learn More

Learn More