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
oddboy
Posts: 136
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1
Accepted Solution

using bb.action.SHARE - odd behaviour

Hi gang,

 

I'm trying to add a Share button to my app.  I'm using an InvokeActionItem.  This seems to be pretty straight forward.

 

When i share text, everything works fine.

 

When i try to share an Image, for some really odd reason, the share menu list (of targets to share to) only has the NFC app.

 

i.e. when sharing test, i see this in the debug.

 

InvocationWrapper::onInvokeFinished: action = "bb.action.SHARE" , target = "sys.invokeTargetSelection" 

 

when i sharing an image, i see this:

 

InvocationWrapper::onInvokeFinished: action = "bb.action.SHARE" , target = "sys.NFCViewer" 

 Here's how the InvokeActionItem looks in each case:

 

Text Only:

actions: [
        InvokeActionItem {
            id: invokeShare
            ActionBar.placement: ActionBarPlacement.OnBar
            title: "Share"
            query {
                mimeType: "text/plain"
                invokeActionId: "bb.action.SHARE"
            }
            onTriggered: {
                data = "This is a test, please stand by.";
            }
        }
    ]

 

 

Sharing Image:

actions: [
        InvokeActionItem {
            id: invokeShare
            ActionBar.placement: ActionBarPlacement.OnBar
            title: "Share"
            query {
                mimeType: "image/jpg"
                invokeActionId: "bb.action.SHARE"
            }
            onTriggered: {
                data = myAppHelper.fullPathToPhoto;
// i.e. : /accounts/1000/appdata/<blah blah blah>/shared/camera//IMG_00000365.jpg } } ]

 

Any ideas what (TF) i'm doing wrong?

 

thanks!

 

 

bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10

Re: using bb.action.SHARE - odd behaviour

[ Edited ]

Everything appears to be correct, but with invocations using QML that hasn't ever really meant much.

 

I decided a long time ago it wasn't even worth bothering with invocations in QML because the results varied so greatly and each update tends to break it in some way or another.

 

Here's a link to a method of doing this using c++ which works =) and is nearly as simple as the qml method, only It works :smileyvery-happy:

 

http://supportforums.blackberry.com/t5/Native-Development/Is-it-possible-to-Postpone-or-further-stre...

 

*to use an image simply have your application pass the images url to c++ as a string(same thing its setup to do with text) then use the string to load the image and place it in your query

Developer
oddboy
Posts: 136
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1

Re: using bb.action.SHARE - odd behaviour

Thanks for the lead!

 

i tried to write my own function, but it doesn't work.  compiles fine, but doesn't work.

 

i think the setUri is a file path (as in /accounts/1000/...) and not an asset path (file:///...).

 

not sure what i've done wrong here.  any ideas?

 

void appHelper::share(QString filename) {
	InvokeManager manager;
	InvokeRequest request;
	qDebug() << "    -> App: entering appHelper::share() with " << filename;

	// Setup what to show and in what target.
	// request.setTarget("sys.settings.targ	et");
	request.setTarget("sys.invokeTargetSelection");
	request.setAction("bb.action.SHARE");
	request.setMimeType("image/jpg");
	// request.setUri(filename);
	request.setUri("/accounts/1000/appdata/<blah blah blah>/shared/camera/IMG_00000418.jpg");
	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);
	}
}

 

bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10

Re: using bb.action.SHARE - odd behaviour

[ Edited ]

when you run it, is qDebug being called with the filepath?

 

you are correct that you need /accounts/<blah>/ without  file:/// in c++

 

I'll try and test this out with an image and post results if i get it working

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

Re: using bb.action.SHARE - odd behaviour

[ Edited ]

on second thought I belive this will do the trick

 

request.setUri(QUrl::fromLocalFile(fileName));

 It's how i'm invoking a picture into a preview viewer

Developer
oddboy
Posts: 136
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1

Re: using bb.action.SHARE - odd behaviour

tried the QUrl::fromLocalFile and nothing happens still.

 

the debug statement in the function prints this to console: 

-> App: entering appHelper::share() with  "/accounts/1000/appdata/<blah blah>/camera/IMG_00000426.jpg" 

 

still stuck.

 

bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10

Re: using bb.action.SHARE - odd behaviour

[ Edited ]

I was giving you instructions for the wrong type of Invocation I apologize

 

I have tested and this code works (for this I belive you will need file:// if so just uncomment the prepend)

 

void ApplicationUI::share(QString fileName)
{

	qDebug() << "fileName - " << fileName ;
	//fileName = fileName.prepend("file://");
	InvokeQuery *query = InvokeQuery::create()
		.uri(fileName);

	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()));
}

 

Developer
oddboy
Posts: 136
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1

Re: using bb.action.SHARE - odd behaviour

well, almost there... i'm not sure where the onArmed() and onFinished() get implemented.

 

i've used your sample code in a Q_INOVKABLE function call in a small helper class, but there is no onArmed() or onFinished().

 

...almost there.. I'm still messing around trying to get my head around it.

 

 

bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com
Developer
oddboy
Posts: 136
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1

Re: using bb.action.SHARE - odd behaviour

ok, m_invocation is a private: variable in my helper class (Invocation *m_invocation).

 

my share() and onArmed() and onFinished() look like this:

 

void appHelper::share(QString fileName) {
	qDebug() << "   -> App: appHelper::share(): fileName - " << fileName ;
		// fileName = fileName.prepend("file://");
		InvokeQuery *query = InvokeQuery::create()
			.uri(fileName).mimeType("image/jpg").data(fileName.toUtf8());

		// Invocation *invocation = Invocation::create(query);
		m_invocation = Invocation::create(query);
		query->setParent(m_invocation); // destroy query with invocation
		m_invocation->setParent(this); // app can be destroyed before onFinished() is called
		// invocation->trigger("bb.action.SHARE");
		connect(m_invocation, SIGNAL(armed()), this, SLOT(onArmed()));
		connect(m_invocation, SIGNAL(finished()), this, SLOT(onFinished()));
}
void appHelper::onArmed() {
	m_invocation->trigger("bb.action.SHARE");
}
void appHelper::onFinished() {
	m_invocation = NULL;
}

 

still not working but some more useful info in the debug output.

 

one thing to note: i get different errors dependon on whether or not i uncomment the line:

 

		// fileName = fileName.prepend("file://");

 with it commented out:

 

   -> App: appHelper::share(): fileName -  "/accounts/1000/appdata/<blah blah>/shared/camera/IMG_00000447.jpg" 
InvocationWrapper::onQueryFinished: no matching result from Menu Service for query
   mimeType="image/jpg"
   uri=QUrl("/accounts/1000/appdata/<blah blah>/shared/camera/IMG_00000447.jpg") 
   data= "/accounts/1000/appdata/<blah blah>/shared/camera/IMG_00000447.jpg" 
   metadata= QMap() 
   perimeter= 0 
   action= "" 
   target= "" 
   invokerIncluded= false 
InvocationPrivate::onQueryResolved: no result matching query, no armed signal sent. 

 with it uncommented:

 

  -> App: appHelper::share(): fileName -   "/accounts/1000/appdata/<blah blah>/shared/camera/IMG_00000446.jpg"
InvocationWrapper::onInvokeFinished: invocation failed with error 2 
Invocation failed for action="bb.action.SHARE", target="sys.invokeTargetSelection", reason="BadRequest"
InvocationWrapper::onInvokeFinished: action = "bb.action.SHARE" , target = "sys.invokeTargetSelection" 

 still going...

 

bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10

Re: using bb.action.SHARE - odd behaviour

[ Edited ]

forgot to add the onArmed/finished in my last comment

 

if the fileName coming from qml does not have file:// uncomment

fileName = fileName.prepend("file://");

with the correct file path this works as it is

.cpp

void ApplicationUI::share(QString fileName)
{

	qDebug() << "fileName - " << fileName ;
	//fileName = fileName.prepend("file://");
	InvokeQuery *query = InvokeQuery::create()
		.uri(fileName);

	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();
}

.hpp

 

public:
    ApplicationUI(bb::cascades::Application *app);
    virtual ~ApplicationUI() { }
    Q_INVOKABLE void share(QString fileName);
public slots:
	Q_INVOKABLE void onFinished();
	Q_INVOKABLE void onArmed();