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
edusal100
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1

invoke the share framework from c++

hi im working on a screenshot sharing funcionality but im having problems with the target invoker, according to my file that is a png, it supposedly use the apps that handles images, but instead send me to foursquare, i dont know if I have to put an specific target or how to make the corrections to send me with the normal invokeActionItem

 

here is my cpp

 

void WeatherNowApp::showPhotoInCard(const QString fileName)
{

    bb::system::InvokeManager manager;
    bb::system::InvokeRequest request;

    // Setup what to show and in what target.
    request.setUri(QUrl::fromLocalFile(fileName));
    request.setAction("bb.action.SHARE");
    InvokeTargetReply *targetReply = manager.invoke(request);

    // Setting the parent to "this" will make the manager live on after this function is destroyed
    manager.setParent(this);

    if (targetReply == NULL) {
        qDebug() << "InvokeTargetReply is NULL: targetReply = " << targetReply;
    } else {
        targetReply->setParent(this);
    }
}

 

hpp

 

public:

 Q_INVOKABLE void showPhotoInCard(const QString fileName);

 

and my qml

 

 QTimer{
          id: timer3
          interval:250
          onTimeout: {
              var filePath = screenshot.captureWindow( "file:data/screenshot.jpg", Application.mainWindow.handle );
              _WeatherNow.showPhotoInCard(filePath);
              timer3.stop();
          }  
        },

        Screenshot{
            id:screenshot   
        }
        

 ActionItem {
                        title: qsTr("Share") + Retranslate.onLocaleOrLanguageChanged
                        imageSource: "asset:///images/048.%20Share.png"
                        
                        onTriggered: {
                            timer3.start();
                        }  

                    }

Retired
erahnenfuehrer
Posts: 85
Registered: ‎05-25-2012
My Device: Limited Edition Z10

Re: invoke the share framework from c++

Make sure you set the mime type:

request.setMimeType("image/png");

 

Developer
edusal100
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1

Re: invoke the share framework from c++

I already make that change, but stills send me to foursquare
Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900

Re: invoke the share framework from c++

If you want the share card to come up you need to use the Invocation class and the armed() signal. https://developer.blackberry.com/native/reference/cascades/bb__cascades__invocation.html?f=Invocatio...
Like all of my posts
Developer
edusal100
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1

Re: invoke the share framework from c++

Tnks, I'm trying to use the invocation, but I'm having problems, can you show me how could I integrate it with what I have?
Retired
erahnenfuehrer
Posts: 85
Registered: ‎05-25-2012
My Device: Limited Edition Z10

Re: invoke the share framework from c++

Check out the Cascades Cookbook C++ Invocation recipe:

 

https://github.com/blackberry/Cascades-Samples/blob/bca485c147fb6b61e8a281f5537fd074ac5cb64a/cascade...

 

Along with the armed signal, note that the InvokeQuery needs to be updated once the data is set:

 

QByteArray queryData = message.toUtf8();
mUnboundQuery->setData(queryData);
mUnboundQuery->updateQuery();

 

Developer
edusal100
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1

Re: invoke the share framework from c++

i know that you point me on the right direction, but i dont know how to work it out on my code, heres from what i understand, but i know its incomplete

 

void WeatherNowApp::showPhotoInCard(const QString fileName)
{

     Invocation m_pInvocation;

     m_pInvocation = Invocation::create(
             InvokeQuery::create()
     .parent(this)
     .URl(QUrl::fromLocalFile(fileName))
     .mimeType("image/png"));
     Qobject::connect(m_pInvocation, SIGNAL(armed()),
             this, SLOT(onArmed()));

 

 m_pInvocation->trigger("bb.action.SHARE");


}

 

Developer
edusal100
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1

Re: invoke the share framework from c++

I got this, but i dont know how to connect the slot onArmed

 

void WeatherNowApp::showPhotoInCard(const QString fileName)
{
    Invocation* m_pInvocation;

    m_pInvocation = Invocation::create(
            InvokeQuery::create()
            .parent(this)
            .uri(QUrl::fromLocalFile(fileName))
            .mimeType("image/png"));
    QObject::connect(m_pInvocation, SIGNAL (armed()),
            this, SLOT(onArmed()));

}

Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900

Re: invoke the share framework from c++

You need to have a method in your WeatherNowApp class that looks like Q_SLOT void onArmed(). Then in there you do m_pInvocation->trigger("bb.action.SHARE");
Like all of my posts
Developer
edusal100
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1

Re: invoke the share framework from c++

yes, thank you, I already figure that out, this the final working code :smileyhappy:

 

C file:

 

void WeatherNowApp::showPhotoInCard(const QString fileName)
{

    m_pInvocation = Invocation::create(
            InvokeQuery::create()
            .parent(this)
            .uri(QUrl::fromLocalFile(fileName))
            .mimeType("image/png"));
    QObject::connect(m_pInvocation, SIGNAL (armed()),
            this, SLOT(onArmed()));
}
void WeatherNowApp::smileysurprised:nArmed(){
    m_pInvocation->trigger("bb.action.SHARE");
}

 

Header:

 

Q_INVOKABLE void showPhotoInCard(const QString fileName);

 

public Q_SLOTS:
    void onArmed();

 


Tnks a lot everyone :smileywink:

 

pd. is there a way to make the transition faster, cause i got a timer for the menu to hide, when the app take the scrrenshot, and then the make the share, but the timer its like 200, and after that seems like it take like 2 seconds, and for example the weather native app, make that in 1 sec