Last Updated: February 25, 2016
· 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">
    <icon> <image>icon.png</image> </icon>
        <property var="uris" value="invocation:"></property>
  • "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 :

    Q_SLOT Q_INVOKABLE void handleInvoke(const bb::system::InvokeRequest&);
    bb::system::InvokeManager* m_invokeManager;
    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;

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

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