Successfully reported this slideshow.
Headless Apps
I am the invisible man.
Who am I?
Founder of Endare
Certified BlackBerry Developer
zezke on the BB Developer fora
@brvandewalle
What is “a headless app”?
A headless application is an application that runs in the background
without a visible UI.
Are all headless apps equal?
Short-running headless apps
maximum run time of 20 seconds
Long-running headless apps
no time...
Long-running headless apps
Requires extended permissions
Yes, a web form
The structure of a HA
Two separate projects in a
single BAR file
UI part (required!)
headless service
How does the headless part start?
Invoked by the system on certain
events (triggers)
sytem.STARTED
PORT_DIRECTED_SMS
PUSH
...
Time for some code
What’s the goal of the demo app?
Water the plants!
Based on location
And ideally on time (like every two days)
1. Create the project
New template in 10.2.1 SDK!
Saves you about 15 minutes of
converting another template
2. Create the UI part
Standard Cascades stuff
a MapView showing your
current location
some data
and a button to set the
ge...
3. Set the geofence (I)
Request permissions
<permission>access_location_services</permission>
Link the necessary libraries...
3. Set the geofence (II)
//Clear the previous geofence
//If you fail/forget to do this you will get an error 257
geomonito...
3. Set the geofence (III)
//Set the geofence
geomonitor_region_t region = NULL;
geomonitor_create_region(&region, "Garden"...
3. Set the geofence (IV)
//Adding the region
int errorCode = geomonitor_add(region);
if (errorCode!= 0){
qWarning()<<"Erro...
4. Handle the invoke (I)
Now we have configured a geofence
Entering this geofence will trigger the headless part to be inv...
4. Handle the invoke (II)
First connect the slot to the signal in the constructor of the headless
service
m_invokeManager-...
4. Handle the invoke (III)
void Service::handleInvoke(const bb::system::InvokeRequest & request) {
if (request.action().co...
5. Trigger a notification (I)
// clear any existing notifications
Notification::clearEffectsForAll();
Notification::delete...
5. Trigger a notification (II)
InvokeRequest invokeReqNotification;
invokeReqNotification.setTarget("com.endare.WaterThePl...
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...
Questions?
Headless Apps on BlackBerry 10.2.1
Upcoming SlideShare
Loading in …5
×

Headless Apps on BlackBerry 10.2.1

918 views

Published on

The code can be found here:
https://github.com/zezke/WaterThePlants

Published in: Technology, Design
  • Be the first to comment

Headless Apps on BlackBerry 10.2.1

  1. 1. Headless Apps I am the invisible man.
  2. 2. Who am I? Founder of Endare Certified BlackBerry Developer zezke on the BB Developer fora @brvandewalle
  3. 3. What is “a headless app”? A headless application is an application that runs in the background without a visible UI.
  4. 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. 5. Long-running headless apps Requires extended permissions Yes, a web form
  6. 6. The structure of a HA Two separate projects in a single BAR file UI part (required!) headless service
  7. 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. 8. Time for some code
  9. 9. What’s the goal of the demo app? Water the plants! Based on location And ideally on time (like every two days)
  10. 10. 1. Create the project New template in 10.2.1 SDK! Saves you about 15 minutes of converting another template
  11. 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. 12. 3. Set the geofence (I) Request permissions <permission>access_location_services</permission> Link the necessary libraries (in the .pro file) -lgeomonitor ( -lQtLocationSubset )
  13. 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. 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. 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. 16. 4. Handle the invoke (I) Now we have configured a geofence Entering this geofence will trigger the headless part to be invoked
  17. 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. 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. 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. 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. 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. 22. Questions?

×