void ApplicationUI::onStopHeadlessService() {
    InvokeRequest request;
    request.setTarget(WAKEME_INVOKE_HEADLESS_SERVICE);
    request.setAction(WAKEME_INVOKE_ACTION_STOPSERVICE);
    _invokeManager->invoke(request);
}
Example #2
0
void App::pushNotificationHandler(bb::network::PushPayload &pushPayload)
{
    // Check for a duplicate push
    PushHistoryItem pushHistoryItem(pushPayload.id());

    if (m_pushNotificationService.checkForDuplicatePush(pushHistoryItem)) {
        // A duplicate was found, stop processing. Silently discard this push from the user
        qWarning() << QString("Duplicate push was found with ID: %0.").arg(pushPayload.id());

        // Exit the application if it has not been brought to the foreground
        if (!m_hasBeenInForeground) {
            Application::instance()->requestExit();
        }

        return;
    }

    // Convert from PushPayload to Push so that it can be stored in the database
    Push push(pushPayload);

    // Save the push and set the sequence number (ID) of the push
    push.setSeqNum(m_pushNotificationService.savePush(push));

    // Create a notification for the push that will be added to the BlackBerry Hub
    Notification *notification = new Notification(NOTIFICATION_PREFIX + QString::number(push.seqNum()),this);
    notification->setTitle("Push Collector");
    notification->setBody(QString("New %0 push received").arg(push.fileExtension()));

    // Add an invoke request to the notification
    // This invoke will contain the seqnum of the push.
    // When the notification in the BlackBerry Hub is selected, this seqnum will be used to lookup the push in
    // the database and display it
    InvokeRequest invokeRequest;
    invokeRequest.setTarget(INVOKE_TARGET_KEY_OPEN);
    invokeRequest.setAction(BB_OPEN_INVOCATION_ACTION);
    invokeRequest.setMimeType("text/plain");
    invokeRequest.setData(QByteArray::number(push.seqNum()));
    notification->setInvokeRequest(invokeRequest);

    // Add the notification for the push to the BlackBerry Hub
    // Calling this method will add a "splat" to the application icon, indicating that a new push has been received
    notification->notify();

    m_model->insert(push.toMap());

    // If an acknowledgement of the push is required (that is, the push was sent as a confirmed push
    // - which is equivalent terminology to the push being sent with application level reliability),
    // then you must either accept the push or reject the push
    if (pushPayload.isAckRequired()) {
        // In our sample, we always accept the push, but situations might arise where an application
        // might want to reject the push (for example, after looking at the headers that came with the push
        // or the data of the push, we might decide that the push received did not match what we expected
        // and so we might want to reject it)
        m_pushNotificationService.acceptPush(pushPayload.id());
    }

    // If the "Launch Application on New Push" checkbox was checked in the config settings, then
    // a new push will launch the app so that it's running in the background (if the app was not
    // already running when the push came in)
    // In this case, the push launched the app (not the user), so it makes sense
    // once our processing of the push is done to just exit the app
    // But, if the user has brought the app to the foreground at some point, then they know about the
    // app running and so we leave the app running after we're done processing the push
    if (!m_hasBeenInForeground) {
        Application::instance()->requestExit();
    }
}
void ApplicationUI::onDisableScanInvokeRequest() {
    InvokeRequest request;
    request.setTarget(WAKEME_INVOKE_HEADLESS_SERVICE);
    request.setAction(WAKEME_INVOKE_ACTION_DISABLESCANINVOKE);
    _invokeManager->invoke(request);
}