BlackBerry Webworks Facebook Post

Facebook integration with an Webworks app, can be a really tricky matter. If you ever tried this you’ve noticed that the Facebook JavaScript SDK, don’t work in the widget and also that the Facebook BlackBerry SDK, is intended for JDE project and also don’t work on a Webworks project.

The best thing that I’ve found in the web that partially solved this, was to use ChildBrowser-plugin-for-BlackBerry, that maybe it used to work, but since some new modifications in the Facebook API, it doesn’t work anymore…

Actually with the ChildBrowser-plugin-for-BlackBerry, I was able to login and retrieve the token using the Torch 9800 simulator, but it just didn’t work for the Bold( device or simulator), so I needed to dive more deeply into it.

I’ve notice this plugin used a BrowserField to connect to Facebook and that it make no sense that it worked on the Torch simulator and not on Bold.

On the Bold device, when I tried to login, it just refreshed the page and didn’t login adding some Security notice.

Since the login worked on any other desktop browser, I’ve opened a sniffer and looked at how was the communication between the browser and Facebook.

Then I’ve also debugged the webworks app and noticed that the only difference between them were that the BlackBerry app was sending an x-wap-profile and maybe this was the reason why Facebook was rejecting the communication.

To be able to set those headers, I needed to create my own ProtocolController, and by doing this I could trick Facebook to think that actually it was a Desktop browser trying to connect. I’ve also had to implement the ability to store and send cookies, and after doing that I was able to connect to Facebook and actually retrieve the token.

Since I used the ChildBrowser-plugin-for-BlackBerry, I think that it’s only fair that I also share my progress, and so you can download it from here BlackBerry-Webworks-Facebook-Post

 

Best regards,

Daniel Botelho

BlackBerry Webworks Javascript Extension to allow File Downloads

If you are a BlackBerry Webworks developer I’m sure you’re always noticing that something is missing.
This time, I took some time to develop something that is really trivial in other plataforms, but due to Webworks nature, it’s bit triky.

My goal was simple: Download an image to the device, and show it in the Webworks app.
So as usual I googled it, and found that are at least one solution for the BlackBerry PlayBook, but not for OS5+.

Since I think that this is useful, I’ve decided to create an Javascript Extension to do this, and you can now download it here

The installation process is as usual, just download that file to your “ext” folder, and make it accessible to the application by adding it to the “config.xml”:

<feature id="blackberry.io.filetransfer" required="false" version="1.0.0"/>

To be able to access those downloaded files through the widget you may need to also add this line to the “config.xml” file:

<access subdomains="false" uri="file:///"/>

With this Javascript Ext you’ll have only one method available:

blackberry.io.filetransfer.download(arguments);

And the “arguments” can be:

  • url (required): Is the download url. ex: “https://www.google.com/images/srpr/logo3w.png”
  • dest (required): Is the local file location. ex:”file:///store/home/user/logo/logo.png”
  • type (optional): Can be ‘POST’ or ‘GET’ (default: ‘GET’)
  • success (optional): Is a Javascript function that is called after the download is complete
  • error(optional): Is a Javascript function that is called if the download fails for some reason
  • headers (optional): For this version the headers only allows you to set the “Authorization” and/or “Content-Type”, but if you need more support please let me know.

And now I’m leaving two examples of how it really works:
Example 1: Download the google logo and notify when it’s done

<script language=”javascript” type=”text/javascript”>

// Here whe need to create the local folder, if it doesn’t exist already
if (!blackberry.io.dir.exists(“file:///store/home/user/logos/”)) {
blackberry.io.dir
.createNewDir(“file:///store/home/user/logos/”);
}

// Download the file
blackberry.io.filetransfer.download({
url: “https://www.google.com/images/srpr/logo3w.png“, // the image url
type : ‘GET’, // explicitly setting method type to ‘GET’
dest: “file:///store/home/user/logos/GoogleLogo.png”, // the local file
success : function(data){ // The function called after the file is downloaded
alert(‘success’);
},
error : function(data){ // The function called if something fails
alert(‘error:’+data);
}
})
</script>

Example 2: Download the google logo with HTTP Basic Authentication

<script language=”javascript” type=”text/javascript”>
function make_base_auth(user, password) {
var tok = user + ‘:’ + pass;
var hash = Base64.encode(tok);
return “Basic ” + hash;
}

// Here whe need to create the local folder, if it doesn’t exist already
if (!blackberry.io.dir.exists(“file:///store/home/user/logos/”)) {
blackberry.io.dir
.createNewDir(“file:///store/home/user/logos/”);
}

// Download the file
blackberry.io.filetransfer.download({
url: “https://www.google.com/images/srpr/logo3w.png“, // the image url
type : ‘GET’, // explicitly setting method type to ‘GET’
headers:{
Authorization: make_base_auth(“my_username”,”my_password”),
“Content-Type”: “application/x-www-form-urlencoded”
},
dest: “file:///store/home/user/logos/GoogleLogo.png”, // the local file
success : function(data){ // The function called after the file is downloaded
alert(‘success’);
},
error : function(data){ // The function called if something fails
alert(‘error:’+data);
}
})
</script>

You can find the source code here https://github.com/dbotelho/blackberry.io.filetransfer

Blackberry Widget dialog and menu conflict issue for OS 6.x

If you have developed a Blackberry Widget app that uses features blackberry.ui.menu and blackberry.ui.dialog in the same application, you’ve noticed that your application won’t work on devices that have OS version 6.x (like the Torch 9800 -6.0.0.227).

To fix this I’ve developed an Javascript Widget Extension that actually does the same as blackberry.ui.dialog but that uses another namespace( to avoid conflict with blackberry.ui.menu).

To use this Widget you should do this:

  • Download the blackberry.ui.dialoger and put this file in projects directory “ext”;
  • Go to applications “config.xml” and replace “blackberry.ui.dialog” for “blackberry.ui.dialoger”
  • Then replace all occurrences of  “blackberry.ui.dialog” for “blackberry.ui.dialoger” in your widget source code
  • And it’s Done!

Now your application can run in both OS 5.x and OS 6.x, and supports dialogs and menu items!

Best regards,

Daniel Botelho

Blackberry Widget with Google Analytics

This is another weird thing! Actually I’ve tried to use Asynchronous Snippet but soon I realise that it didn’t work properly in the widget since it would only track the pageView for the first time the widget loaded.

So I’ve decided to use the same code that I use in this website, and everything works!

To track a pageView I use this code:

pageTracker._trackPageview(‘<page_name>’);

To track an event I use this:

pageTracker._trackEvent(‘<category>’, ‘action’, ‘label’);

If you still can’t use Google Analytics in your BB Widget is because maybe you forgot to add :

<access subdomains=”true” uri=”http://www.google-analytics.com”/>
<access subdomains=”true” uri=”https://ssl.google-analytics.com”/>

to your widget permissions!

Blackberry simulator JVM Error 545

“JVM Error 545 incompatible or corrupt file system”

I’m getting this all the time when starting Blackberry simulator from the Eclipse. Usually to solve this I reinstall the JDE and everything is fine, but now I realised that is only needed to remove the “.dmp” files from the simulator directory!