Category Archives: code

How to invoke the Classic Camera app

The Classic Camera app can be invoked using the following code…

InvokeManager mInvokeManager = new InvokeManager(this);
      bb::system::CardDoneMessage&)), this,
InvokeRequest request;

The response data contains the file name of the captured image.

Thoughts on BlackBerry Cascades from 2011

Flipping through an old notebook, I came across my notes on BlackBerry Cascades from BlackBerry DevCon 2011. This was half a year before the framework was released, and a good year and a half before the launch of BlackBerry 10. Since then I have become an expert at Cascades, but it is interesting to see some of my earlier thoughts.IMG_20150311_233508_crop

  • 2D and 3D
  • 90% of UI could be lists
  • QML declarative UI from Qt
  • Asynchronous to help rendering rate
  • Signals to handle events
  • List Types – (SQL,XML,JSON)
  • Uses BBX IDE
  • QML looks nicer than C++
  • Beta in fall (November)
  • Everything in BBX is Qt

Somethings I got right, and with some others I look a little silly. For example Cascades has no support for 3D. In fact Cascades is actively bad at working in three dimensions and doesn’t even support giving z-values to elements. Also the beta wasn’t launched in November (at the time only a month away), but instead the next May. The emphasis on lists was a bit overblown. Creating 90% of an app out of lists can be true for pretty much any framework, and somewhat ironically I don’t actually use a ListView for creating the lists in most of my apps anyhow. The one thing that was apparent to me from the very beginning is that QML is far nicer than C/C++ ever was…

How to get a Slider to stop at discreet points on a Windows Phone app

By default the Slider control that Microsoft provides for Windows Phone Silverlight applications is missing some key properties such as the IsSnapToTickEnabled property. However this can be recreated in code to give Windows Phone apps the same functionality.

First the XAML…

<Slider x:Name="slider" Width="450" ValueChanged="Slider_ValueChanged" Minimum="0" Maximum="10" SmallChange="1"/>

Then in C#…

public void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
            int newValue = (int)e.NewValue;
            slider.Value = newValue;

            //code goes here, using newValue
            //as the slider's value...
        catch (Exception) { }

Amazon Appstore testing BlackBerry phones

Below is screen shot of an app acceptance email I received from Amazon. In addition to the many Kindle devices, and the lone “Non-Amazon Android” device, you will find the BlackBerry Classic and the BlackBerry Passport.


With the Amazon appstore now preloaded on newer BlackBerry phones, Amazon now appears to explicitly be checking submitted Android apps on these phones. Given the unique screen ratios on these phones, and the fact that they are outselling most of the other devices on this list, it is nice to see Amazon explicitly checking for compatibility. This should free BlackBerry users from having to wonder if anything they download from Amazon will work on their phones.

Creating a Rounded Rectangle in OpenGL

OpenGL is an extremely low level language, and is more or less only capable of drawing triangles. This means that many of the basic shapes that developers are used to having available in a drawing API are not present and must be created from scratch. The below code demonstrates how to draw a rounded rectangle in OpenGL.

static const GLfloat roundRect[] = {

static const GLfloat vbox[] =
    0.0f, 0.0f,
    1.0f, 0.0f,
    0.0f, 1.0f,
    1.0f, 1.0f,

void render()
    glVertexPointer(2, GL_FLOAT, 0, vbox);
    glScalef(.75, .75, 1.0f);
    glVertexPointer(2, GL_FLOAT, 0, roundRect);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 40);

Careful observation of the code (especially the line glDrawArrays(GL_TRIANGLE_FAN, 0, 40);) will point out that that technically OpenGL is once again just drawing a collection of 40 triangles in order to create the rounded rectangle shape.

Processing .html files as PHP

In the interest of having cleaner URLs (or simply to maintain existing links) it is often desirable for webpages to end in a .html extension even if they need to be processed as PHP. On Apache servers this is very straight forwards and you just add the following lines of code to your .htaccess file

AddType x-mapp-php5 .php .htm .html

On Windows servers this is slightly more complicated (as are most things). You need the following code in your web.config file and the value for the scriptProcessor is based on the install location of your php-cgi.exe file. Finding the location of this file can often be teased out by looking at the results from the phpinfo(); command.

<?xml version="1.0" encoding="UTF-8"?>
            <add name="PHP_via_FastCG1" path="*.htm" verb="*" modules="FastCgiModule" scriptProcessor="C:\PHP5.5\php-cgi.exe" resourceType="Either" />
            <add name="PHP_via_FastCG2" path="*.html" verb="*" modules="FastCgiModule" scriptProcessor="C:\PHP5.5\php-cgi.exe" resourceType="Either" />

Creating new projects to optimize BlackBerry 10 apps

Since first releasing the BlackBerry 10 SDK in early 2012, BlackBerry has continued to work on improving their tools. I have recently discovered that significant optimizations are made in newly created Cascades projects. I am currently working on an update to my Stuff I Need app, and have been able to get a 17% reduction in the app’s file size simply by recreating the project from scratch in Momentics. In addition to the smaller install size, the app also appears to be launching quicker. This was done with no changes at all to my code. Using all of the same assets, qml, and c++ files, I created a new project, and then copied my existing files in. The new project contains a few changes to the .pro and the bar-descriptor.xml files, but the majority of the changes seem to be taking place behind the scenes. So for anyone that has been writing BlackBerry Cascades apps for a while now, it may be worth it to recreate your apps and get some free optimizations to your code.

How to get a TextBox in a Windows 8 app to support auto-capitalization

Unlike with most platforms, TextBox controls in Windows 8 metro apps default to a lowercase keyboard instead of assuming that the first word of a sentence should be capitalized. This can be frustrating for users of virtual keyboards who would rather use less keystrokes and let the OS take care of basic formatting. The fix for this is non-obvious, but fortunately quite simple. The solution consists of making sure that spell check is enabled for the TextBox.

This can be done either in XAML with

<TextBox IsSpellCheckEnabled="True" />

or in C# with

TextBox tb = new TextBox();
tb.IsSpellCheckEnabled = true;

How to sideload apps onto WindowsRT devices

With WindowsRT Microsoft has made a bit of an odd platform that only accepts apps from the Windows store and does not provide a simple way to install any custom built apps. The easiest way to sideload an app onto a WindowsRT tablet is to set it up as a developer test device. Unfortunately this does require you to be able to log-in to a Microsoft developer account. Not only is this account not free, but you will be required to reconfirm your credentials every three months. Still this is far easier then the other options to sideload onto WindowsRT.

Step one:

First you need to find the Windows PowerShell app open it using the “Run as administrator” option. Then confirm yes at the UAC prompt. Open the keyboard to type Show-WindowsDeveloperLicenseRegistration and hit enter. Then agree to the prompt, and then log-in to your developer account.

Step two:

In Visual Studio create a Windows Store app in the same manner you would as if you were planning on releasing the app to the store. However once the executable is generated in the AppPackages folder, instead of uploading the .appxupload file find the similarly named test folder and transfer this whole folder onto your WindowsRT device. For WindowsRT devices without support for USB drives this is a challenge all on its own, where the best solution may be to email yourself a .zip file.

Step three:

Now with the folder on your WindowsRT tablet find the Add-AppDevPackage.ps1 file, touch and hold to bring up the right-click menu and select “Run with PowerShell”. Confirm that you do in fact want to open the file, and then follow the multiple prompts within PowerShell. Eventually the app will load and you will be able to run the app as if you had installed it from the app store.

An intro to the Amazon Appstore

As BlackBerry prepares to have the Amazon appstore preinstalled on their phones, I have already had my apps in the Amazon store for two years now.

First of all the best place to have your apps is in BlackBerry AppWorld. If you are writing a native Cascades app, there is no choice except to sell your apps through the BlackBerry store. If you are selling an app based on a cross platform framework such as Cordova or Unity you are better off compiling that code natively to a .bar file as it will run much better then packaging the same code as an Android app. If you have a native Android app, then you are still better off compiling to a .bar file and submitting the app to BlackBerry World. Taking this extra step makes the app easier for users to update and also gives developers the possibility of removing the back bar from apps.

However, simply having the ability to sell to Amazon’s own tablets and phones is enough reason reason to submit your apps into the store.


For the most part the Amazon store is pretty similar to what all other platforms offer with developers getting a 70% cut of all sales. Payments are made out to developers via direct deposit to a bank account. All apps are submitted as .apk files and like Android apps on BlackBerry, they must not be dependent upon any Google Play services. All apps submitted to the Amazon Appstore require a minimum of three screenshots (at one of a few specific resolutions), and are subjected to a rather comprehensive review policy. App reviews typically take around five days, with rejections usually a case of including a reference to the Google Play store (including something as simple as a link to your other Android apps).

The high praise that BlackBerry has given the Amazon store is mostly marketing fluff. The truth of the matter is that nobody cares about Amazon coins, and this store really isn’t all that different than all of the others…

Adding Cascades highlight colors (without losing the ability to theme 10.2)

PinkWith the release of BlackBerry 10.3 later this year Cascades apps will have the ability to set a custom highlight color. While this is typically defined in the bar-descriptor.xml file, doing so will prevent any theme from being applied when the app is run on phones running an older operating system. Fortunately there is a workaround. (Thanks to Derek Konigsberg for pointing out how to do this).

In short you can override the CASCADES_THEME environmental variable in the brief window between the app being launched, and the creation of the app’s UI. The following code sets a dark theme with pink highlights when run on OS 10.3 and sets a simplier dark theme for older OS versions.

Q_DECL_EXPORT int main(int argc, char **argv)
    bb::platform::PlatformInfo p_info;
    QString ver = p_info.osVersion();

    if(ver.startsWith("10.0") || ver.startsWith("10.1") || ver.startsWith("10.2"))
        qputenv("CASCADES_THEME", "dark");

    Application app(argc, argv);
    MileageTrackerApp mainApp(&app);
    return Application::exec();

The recently updated Mileage Tracker app (pictured above) is an example of an app that is using this technique.

Cascades code change in BlackBerry 10.3

There is a slight change in Cascades 10.3 dealing with conditional variables based off of the length of the hint text of a field. For example the following code (designed to only show the TextField when the hint text is not an empty string) would work on BlackBerry 10.2 but fails when run on BlackBerry 10.3

    property alias hint:newTextField.hintText
    property alias text:lbl.text

Fortunately the work around for this is extremely simple. You just need to create (and set) an additional alias for the visibility of the field. This is shown below…

    property alias hint:newTextField.hintText
    property alias text:lbl.text
    property alias showTextField:newTextField.visible

Using the Ionic framework for BlackBerry apps

ionic_logoI have made claims about my Erie Canal app being the first BlackBerry app to make use of the Ionic framework, so it should be worth pointing out how this was done. Technically the Ionic framework only support iOS and Android, but it is based off of Cordova just like BlackBerry’s Webworks framework is. Knowing how well BlackBerry 10 supports HTML5 I assumed that it was likely that supporting this new framework would be no trouble at all.

Using either BlackBerry Webworks or the Ionic Framework require quite a bit of set up involving the installation of Node.js and Cordova but once everything is set up, the process is fairly simple. First create two separate instances of your new project, one with the Ionic framework, and one with BlackBerry webworks. Then copy over the www/lib folder from the Ionic project to the BlackBerry project. This folder includes all of the css and javascript that make up the Ionic framework (and also includes the libraries needed to support angular.js). Once this folder is included, BlackBerry HTML5 apps can be compiled as normal.

In fact the entire www folder can be shared between BlackBerry, Android, and iOS versions of the app with the platform differences mostly taking place in manifest files and the actual compilation of the apps.

Potential concerns with the odd resolution of the Z3

After spending months refusing to be honest with developers about the specs for the Z3, it has finally been revealed that the phone has a 540×960 resolution. For developers the phone presents itself as 720×1280 device and then downscales the content to 75% of the size, which is exactly what I predicted two months ago.

While BlackBerry claims that this will work flawlessly and magically, that is not exactly the case. Downscalling content such as this has some issues, mainly that any UI elements that are only a single pixel wide have a one in four chance of disappearing completely. Scaling can work, but it is best when you are scaling up and are doing so by a power of two. This is why iOS devices doubled their horizontal and vertical resolutions when they switched to a higher res format.

In fact, any element with a size less than 4 pixels has the possibility of looking to be a bit off. The images below show the result of scaling a 1×1 pixel grid (in pink), a 2×2 pixel grid (in blue), and a 4×4 pixel grid (in orange).




Grids are kindof a worst case scenario, so most apps actually won’t look too bad. But nothing is going to look great.

What is worse is that the device really believes itself to be a different resolution than it is. As such developers have no simulator, and screenshots are the same 720×1280 resolution that the Z30 produces. This also implies that all text (which is full of the thin strokes that are susceptible to issues) also goes through this identical scaling process.

At $190 the BlackBerry Z3 is not significantly cheaper than the Z10, so there is no reason that this should be your smartphone of choice. Pay a little extra and get something better.