Saturday, June 7, 2014

Geting Call notification from Cascades QML code in BB10

I was updating my Audiobook Reader application. I wanted to listen to our going or incoming call and pause book accordingly.

BB10 provides nice API to control call and listen to it.

This post will show how we can listen to call from Cascades QML code. First we need to ask for access_phone and control_phone permission in our bar descriptor file.
Now we need to link system lib to our app.
LIBS += -lbbsystem 
Once this is done, we need to register Phone type to QML system so we can access it from QML.

#include <bb/system/phone/Phone>
using namespace bb::system;

int main(int argc, char **argv) {
    qmlRegisterType("", 1, 0, "Phone");
Now we are ready to use Phone API from QML side. Following is how QML code will look like. In code we are creating Phone object. On any call related event callUpdated signal will be called. So we are handling that signal in onCallUpdated event. Please note that we can not access Call's properties with QML, as its not derived from QObject, so if you need to access properties of Call then you need to forward call to C++ and handle it there.

import bb.system 1.0
import 1.0

Page {
    attachedObjects: [
        Phone {
            id: phone
            onCallUpdated: {
                console.log(" ############## Phone::onCallUpdated ") ; 
                //do the needful
Thant's it. Hope it will be helpful.

1 comment:

  1. I am developing an app about sms-blocked.

    Here is the problem:the notifications (instant preview) is triggered before the message received! But how to prevent the notification when the sms is blocked in MessageService::messageReceived slot?

    I want to change the profile to 'AlertOff" mode when blocked sms received.but I found the instant preview notification is show out before the messageReceived signal triggerd.