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
New Contributor
Posts: 6
Registered: ‎08-28-2013
My Device: -
Accepted Solution

Share link

Hi all,

I want to share a link to appworld (a link to my app) using Invocation. My code (in QML) is:

 

 

Button{ text: "Share"

    onClicked: {

        invokeQuery.mimeType = "text/plain"
                    invokeQuery.data = "Try this app: < a href=\"appworld://content/xxxxxxxx\">My app </ a>.";
                    
                    invokeQuery.updateQuery();

}

 

...

 

attachedObjects: [

Invocation {
                id: invokeShare
               
                query: InvokeQuery {
                    id:invokeQuery
                    mimeType: "text/plain"
                }
                onArmed: {
                    if (invokeQuery.data != "") {
                        trigger("bb.action.SHARE");
                    }
                }            
            } }

 

 

But I get a plain text and i want that user click the link and be redirected to appworld. How I can do?

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Share link

Can you clarify what you're actually trying to do? If it's just programmatically opening the BBWorld app on your app's own page, this is way too complicated for that. See this post, especially the link to the documentation which describes the specific properties required: http://supportforums.blackberry.com/t5/Native-Development/BB-World-invocation-in-10-2-issue/m-p/2569...

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
New Contributor
Posts: 6
Registered: ‎08-28-2013
My Device: -

Re: Share link

I want to put a button in my app that allow to share a message (BBM, mail, chat, etc) that invite a friend to try my app.

Developer
Posts: 824
Registered: ‎10-16-2012
My Device: Red Z10

Re: Share link

[ Edited ]

the QML invocation has always been tricky and generaly never works properly unless used with a context action item.

 

This can easily be done using c++

 

ApplicationUI.cpp

#include <bb/cascades/InvokeQuery>
#include <bb/cascades/Invocation>
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    qml->setContextProperty("cpp", this);
void ApplicationUI::message()
{
	QString text = "Download Dev Mode for Free in BlackBerry World!  http://appworld.blackberry.com/webstore/content/35407898";

	InvokeQuery *query = InvokeQuery::create()
		.mimeType("text/plain")
		.data(text.toUtf8());
	Invocation *invocation = Invocation::create(query);
	query->setParent(invocation); // destroy query with invocation
	invocation->setParent(this); // app can be destroyed before onFinished() is called

	connect(invocation, SIGNAL(armed()), this, SLOT(onArmed()));
	connect(invocation, SIGNAL(finished()), this, SLOT(onFinished()));
}

void ApplicationUI::onArmed() {
	Invocation *invocation = qobject_cast<Invocation *>(sender());
	invocation->trigger("bb.action.SHARE");
}

void ApplicationUI::onFinished() {
	Invocation *invocation = qobject_cast<Invocation *>(sender());
	invocation->deleteLater();
}

 ApplicationUI.hpp

 

namespace bb
{
    namespace cascades
    {
        class Application;
        class Invocation;
    }
}

 

public: 
        Q_INVOKABLE void message();

public slots:
	Q_INVOKABLE void onFinished();
	Q_INVOKABLE void onArmed();

 

QML

 

Button {
   onClicked: {
         cpp.message();
   }
}

 
I don't belive it's required, but if you run into any issues compiling try adding this to your .pro

 

.pro

LIBS += -lbbsystem
Regular Contributor
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone

Re: Share link

[ Edited ]

just add the following code in your qml file

 

and it will open bb share card

from where you can share the content you want

 

     Button{
                                    
                                    id: btnshare
                                    onClicked: {
                                        share.trigger("bb.action.SHARE")
                                    
                                    }
                                    
                                    attachedObjects: [
                                    Invocation {
                                        id: share
                                        query {
                                            mimeType: "text/plain; charset=utf-8"
                                            invokeActionId: "bb.action.SHARE"
                                            data&colon; "abc"
                                        }
                                    }
                                
                                ]
                              
                            
                            }

 

please accept the solution, if it works

New Contributor
Posts: 6
Registered: ‎08-28-2013
My Device: -

Re: Share link

Thank you! Just what I wanted!