Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 33
Registered: ‎08-28-2013
My Device: non-BlackBerry user

Invocation with QML for Headless Application

Hello guys, I wanna ask you a question about triggering Headless Application using "Invocation" inside QML file. I want to use Notfication service and hope you guys can help me out.

 

I should indicate I am using QNX Momentics Version: 2.1 with 10.3 Native SDK. Below you can see all the steps that I took in detail:

1) I created a BB project with a template "Headless app" and named the project as "PushNotification".

2) Now, in my project explorer I have two projects which are "PushNotification" and "PushNotificationService".

3) I opened "main.qml" in the assets folder of "PushNotification" project and saw that under "onClicked:" function of the button, there is "app.resendNotification();" statement. 

4) I opened "applicationui.cpp" in the src folder of "PushNotification" project and navigated to "void ApplicationUI::resendNotification()" method. Below you can see the code inside of this method.

void ApplicationUI::resendNotification()
{
    InvokeRequest request;
    request.setTarget("com.example.PushNotificationService");
    request.setAction("com.example.PushNotificationService.RESET");
    m_invokeManager->invoke(request);
    Application::instance()->minimize();
}

 5) Now I opened back "main.qml" in the assets folder of "PushNotification" project. I commented out "app.resendNotification();" statement and inserted different Invocation objects because I wanted to do this invocation via qml file not cpp file. Below you can see my modified code inside main.qml file.

/*
 * Copyright (c) 2013-2014 BlackBerry Limited.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import bb.cascades 1.3
import bb.system 1.2

Page {
    Container {
        Label {
            // Localized text with the dynamic translation and locale updates support
            text: qsTr("PushNotification Service says Hello!") + Retranslate.onLocaleOrLanguageChanged
        }
        Button {
            text: qsTr("Resend Notification") + Retranslate.onLocaleOrLanguageChanged
            onClicked: {
                // app.resendNotification();
                invokeQuery.updateQuery();
                invokeNotifyQuery.updateQuery();
                invokeNotificationQuery.query.updateQuery();
            }
        }
        attachedObjects: [
            InvokeQuery {
                id: invokeQuery
                mimeType: "text/txt"
                invokeTargetId: "com.example.PushNotificationService"
                invokeActionId: "com.example.PushNotificationService.RESET" 
            }
            ,
            Invocation {
                property bool auto_trigger: false
                query { 
                    InvokeQuery {
                        id: invokeNotifyQuery     
                        invokeTargetId: "com.example.PushNotificationService"
                        invokeActionId: "com.example.PushNotificationService.RESET" 
                    }   
                }
                onArmed: {
                    if (auto_trigger) {
                        trigger("com.example.PushNotificationService.RESET");
                    } else {
                        auto_trigger = true;
                    }
                }
            }
            ,
            InvokeActionItem {
                id: invokeNotificationQuery
                query {
                    invokeTargetId: "com.example.PushNotificationService"
                    invokeActionId: "com.example.PushNotificationService.RESET" 
                }
            }
        ]
    }
}

 

6) I tried all these 3 different InvokeQuery, Invocation and InvokeActionItem one by one. None of them worked. When I try to invoke InvokeQuery object it gives following output:

InvocationWrapper::onQueryFinished: menu service population failed
  query mimeType=""
  query uri=""
  query data=""
  query metadata=QMap() 
  query action= "com.example.PushNotificationService.RESET" 
  query target= "com.example.PushNotificationService" 
  query perimeter= 0 
  invokerIncluded= false 
  MenuManager.error()= 1 
InvokeActionItemPrivate::updateActionSet: final query state = "Failed" 

 When I try to invoke Invocation object it gives following output:

InvocationWrapper::onQueryFinished: menu service population failed
  query mimeType=""
  query uri=""
  query data=""
  query metadata=QMap() 
  query action= "com.example.PushNotificationService.RESET" 
  query target= "com.example.PushNotificationService" 
  query perimeter= 0 
  invokerIncluded= false 
  MenuManager.error()= 1 
InvocationPrivate::onQueryResolved: query failed, no armed signal sent. 

  When I try to invoke InvokeActionItem object it gives following output:

InvocationWrapper::onQueryFinished: menu service population failed
  query mimeType=""
  query uri=""
  query data=""
  query metadata=QMap() 
  query action= "com.example.PushNotificationService.RESET" 
  query target= "com.example.PushNotificationService" 
  query perimeter= 0 
  invokerIncluded= false 
  MenuManager.error()= 1 
InvokeActionItemPrivate::updateActionSet: final query state = "Failed" 

 

My question is could you help me making this invocation request inside qml file properly? 

 

I might be doing something very silly so try not to make fun of me too much (:

 

Thank you for your help !!