7v_vda
Last Updated: February 25, 2016
·
3.524K
· adinugroho

Invoke App from Browser/Other App using Custom URL

In bar-descriptor.xml add the following xml :

<!-- invocation target -->
<invoke-target id = "com.example.InvocationTest">
    <invoke-target-type>application</invoke-target-type>
    <invoke-target-name>InvocationTest</invoke-target-name>
    <icon> <image>icon.png</image> </icon>
    <filter>
        <action>bb.action.VIEW</action>
        <action>bb.action.OPEN</action>
        <mime-type>*</mime-type>
        <property var="uris" value="invocation:"></property>
    </filter>       
</invoke-target>
  • "id" must be the same as your app id
  • you must provide icon, it's recommended to use the same app icon as invocation icon

In main_application class (not main.cpp but your application class), momentics IDE automatically create applicationui class if you choose cascades project.

applicationui.hpp :

public:
    Q_SLOT Q_INVOKABLE void handleInvoke(const bb::system::InvokeRequest&);
private:
    bb::system::InvokeManager* m_invokeManager;
Q_SIGNALS:
    void gotData(QString, QString);
  • InvokeManager is class to manage invocation
  • handleInvoke method act like a listener when invocation happen
  • gotData signal is just a signal to send data to object in qml

applicationui.cpp :

using namespace bb::system;

//constructor
ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app)
{
    m_invokeManager = new InvokeManager(this);
    QObject::connect(m_invokeManager, SIGNAL(invoked(const bb::system::InvokeRequest &)), this, SLOT(handleInvoke(const bb::system::InvokeRequest &)));
    // your code
}

//listener
void ApplicationUI::handleInvoke(const InvokeRequest& request)
{
    QString uri = request.uri().toString();
    QString data = QString::fromUtf8(request.data());
    qDebug() << "INVOKE RESULT: " << uri << " " << data;
    emit gotData(uri, data);
}
  • use bb::system namespace (to use InvokeManager class)
  • create new InvokeManager instance
  • define handler/listener for this app invocation
  • create listener method with parameter request for the request and data that's sent from browser/other app

Dont forget to add this line on .pro file :

LIBS += -lbbsystem

Source : link