Headless Apps on BlackBerry 10.2.1

Uploaded on

The code can be found here: …

The code can be found here:

More in: Technology , Design
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads


Total Views
On Slideshare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Headless Apps I am the invisible man.
  • 2. Who am I? Founder of Endare Certified BlackBerry Developer zezke on the BB Developer fora @brvandewalle
  • 3. What is “a headless app”? A headless application is an application that runs in the background without a visible UI.
  • 4. Are all headless apps equal? Short-running headless apps maximum run time of 20 seconds Long-running headless apps no time limit All are limited to: 7 to 25 percent of CPU at any given time limited to 3MB of memory
  • 5. Long-running headless apps Requires extended permissions Yes, a web form
  • 6. The structure of a HA Two separate projects in a single BAR file UI part (required!) headless service
  • 7. How does the headless part start? Invoked by the system on certain events (triggers) sytem.STARTED PORT_DIRECTED_SMS PUSH GEOREGIONEXIT GEOREGIONENTER By any UI application via an invoke target
  • 8. Time for some code
  • 9. What’s the goal of the demo app? Water the plants! Based on location And ideally on time (like every two days)
  • 10. 1. Create the project New template in 10.2.1 SDK! Saves you about 15 minutes of converting another template
  • 11. 2. Create the UI part Standard Cascades stuff a MapView showing your current location some data and a button to set the geofence
  • 12. 3. Set the geofence (I) Request permissions <permission>access_location_services</permission> Link the necessary libraries (in the .pro file) -lgeomonitor ( -lQtLocationSubset )
  • 13. 3. Set the geofence (II) //Clear the previous geofence //If you fail/forget to do this you will get an error 257 geomonitor_remove("Garden");
  • 14. 3. Set the geofence (III) //Set the geofence geomonitor_region_t region = NULL; geomonitor_create_region(&region, "Garden"); geomonitor_region_set_circle_shape(region, latitude, longitude, 100.0); geomonitor_region_set_monitoring_mode(region, GEOMONITOR_MONITORING_MODE_PERSISTENT); geomonitor_region_set_notification_invoke_target(region, "com.endare.WaterThePlantsService", GEOMONITOR_NOTIFICATION_DIRECT); //Adding the region int errorCode = geomonitor_add(region); if (errorCode!= 0){ qWarning()<<"Error occurred with code " << QString::number(errorCode) << endl; } else { qDebug() << "Geofence set!";
  • 15. 3. Set the geofence (IV) //Adding the region int errorCode = geomonitor_add(region); if (errorCode!= 0){ qWarning()<<"Error occurred with code " << QString::number(errorCode) << endl; } else { qDebug() << "Geofence set!"; } geomonitor_destroy_region(&region);
  • 16. 4. Handle the invoke (I) Now we have configured a geofence Entering this geofence will trigger the headless part to be invoked
  • 17. 4. Handle the invoke (II) First connect the slot to the signal in the constructor of the headless service m_invokeManager->connect(m_invokeManager, SIGNAL(invoked(const bb::system::InvokeRequest&)), this, SLOT(handleInvoke(const bb::system::InvokeRequest&)));
  • 18. 4. Handle the invoke (III) void Service::handleInvoke(const bb::system::InvokeRequest & request) { if (request.action().compare("bb.action.GEOREGIONENTER") == 0) { qDebug() << "Service:: entered the georegion"; triggerNotification(request); } else { qDebug() << "Service:: unknown service request " << request.action(); } }
  • 19. 5. Trigger a notification (I) // clear any existing notifications Notification::clearEffectsForAll(); Notification::deleteAllFromInbox(); // turn on previews in settings bb::platform::NotificationDefaultApplicationSettings settings; settings.setPreview(bb::platform::NotificationPriorityPolicy::Allow); settings.apply();
  • 20. 5. Trigger a notification (II) InvokeRequest invokeReqNotification; invokeReqNotification.setTarget("com.endare.WaterThePlants"); //Setting the content of the body QString body; body = “Don’t forget to water your plants!”; //Setting the body and the InvokeRequest of the notification _notification.setBody(QString::fromUtf8(body.toAscii())); _notification.setInvokeRequest(invokeReqNotification); //Displaying the Instant Preview _notification.notify();
  • 21. Conclusion It works But slowly (takes up to three hours to fire at the moment) might be a bug A lot of future work include time aspect
  • 22. Questions?