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
nicklas
Posts: 150
Registered: ‎02-01-2009
My Device: Torch, PlayBook and Dev Alpha
My Carrier: SFR

Invocation sample

Hi,

 

As someone asks me an Invokation sample, I share my code :smileyhappy:

 

bar-descriptor.xml :
====================

<your prefix> : com.domain.application.openhandler

<qnx>
      <!-- Invokation framework -->
      <invoke-target id="<your prefix>.openhandler">
      <type>APPLICATION</type>
         <filter>
            <action>bb.action.OPEN</action>
            <mime-type>*</mime-type>
            <property var="uris" value="file://"/>
         </filter>
      </invoke-target>
</qnx>

 In this sample, my application can be called to OPEN any (mime-type = *) local (uris = file://) file in a new windows (APPLICATION)

Of course, you can change the filter, declare several invoke target.

 

And your C++ code :
===================

In your main class constructor :

MyApp:MyApp(Application &app, 
		QTranslator &translator, QString &currentLocale) {
  // Invocation framework init
  initInvokationReceiving();
}


void MyApp::initInvokationReceiving(void) {
  InvokeManager *iManager = new InvokeManager(this);

  QObject::connect(iManager, 
	SIGNAL(invoked(const bb::system::InvokeRequest&)),
	this, 
	SLOT(onHandleInvoke(const bb::system::InvokeRequest&)));

  switch (iManager->startupMode()) {
  case ApplicationStartupMode::LaunchApplication:
    // Launched from homescreen
    break;
  case ApplicationStartupMode::InvokeApplication:
  case ApplicationStartupMode::InvokeViewer:
  case ApplicationStartupMode::InvokeCard:
    // Invocation. Anticipate a call to handleInvoke() slot
    break;

  default:
    break;
  }
}

void MyApp::onHandleInvoke(const InvokeRequest& request) {
  // If the client is also a target
  // QString source = request.source();
  // If it is a bound invocation
  QString target = request.target();
  // The action to be performed
  QString action = request.action();
  // Content type of the data
  QString mime = request.mimeType();
  // Location of data – out of band
  QString uri = request.uri().toString();
  // In-band data
  QString data = QString(request.data());
  
  // qDebug() << "source: " << source;
  qDebug() << "target: " << target;
  qDebug() << "action: " << action;
  qDebug() << "mime:   " << mime;
  qDebug() << "uri:    " << uri;
  qDebug() << "data&colon;   " << data;
}

 

initInvokationReceiving permits to change your init behavior in function your startup mode. Sample, if your start-up mode is "Card", you don't create an application menu.

At last, in init, I register my callback SLOT to read the params sent by the application caller.

 

In onHandleInvoke, I read all params.

 

When your app is called from an other app, OS10 call your main constructor, then the onHandleInvoke will be called.

 

Nicolas

 

Please use plain text.
Regular Contributor
senimii
Posts: 50
Registered: ‎04-27-2012
My Device: BlackBerry Q10
My Carrier: 447713279379

Re: Invocation sample

connect(m_invokeManager, SIGNAL(invoked(const bb::system::InvokeRequest&)), this, SLOT(handleInvoke(const bb::system::InvokeRequest&)));

 

// Initialize properties with default values
switch (m_invokeManager->startupMode()) {
case ApplicationStartupMode::LaunchApplication:
m_startupMode = tr("Launch");
break;
case ApplicationStartupMode::InvokeApplication:
m_startupMode = tr("Invoke");
break;
case ApplicationStartupMode::InvokeCard:
m_startupMode = tr("Card");
break;
}

 

What is the difference between using the handleInvoke and onHandleInvoke?

 

 

 

 

 

 

NFC on my mind!!
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Invocation sample

It's just the name of the target method. You can have any name you like. "on" and "do" are prefix conventions from various development platforms that have no significant meaning other than it reinforces what is being done by the method. No different than having an prefix on the variables (e.g. m_) to reinforce the meaning of the variable. Not needed, just a convention left over from older development environments where the variable name enforced the variable type.
Please use plain text.
New Contributor
Kevin2020
Posts: 6
Registered: ‎01-24-2013
My Device: 10
My Carrier: 10

Re: Invocation sample

Hi , I want find a way to invoke a settting screen as a card.  Can  I do this in qml . Please give me some advise. Thanks a lot.

Please use plain text.
Regular Contributor
senimii
Posts: 50
Registered: ‎04-27-2012
My Device: BlackBerry Q10
My Carrier: 447713279379

Re: Invocation sample

This article helped me alot on that....

 

https://appbus.wordpress.com/2012/11/08/invoke-cards/#viewSource

NFC on my mind!!
Please use plain text.
BlackBerry Development Advisor
shaque
Posts: 231
Registered: ‎07-14-2008
My Device: Not Specified

Re: Invocation sample

Please use plain text.
Developer
laurentC
Posts: 266
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: Invocation sample

Hello, First of all, thanks a lot for the sample. I'm trying to make my app "invocable" ie when the user select some text and click the share icon, I want my app to be opened with the text selected by the user inside a textarea. But I can't figure out how to modify my bar-descriptor.xml file : APPLICATION bb.action.OPEN * mime-type ? --> maybe text/plain property var ??? Thks, Laurent
Twitter : @LaurentKP
My apps
Please use plain text.
BlackBerry Development Advisor
shaque
Posts: 231
Registered: ‎07-14-2008
My Device: Not Specified

Re: Invocation sample

Try registering a filter in the bar-descriptor with,
action: bb.action.SHARE
mime: text/plain
Please use plain text.
Developer
laurentC
Posts: 266
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: Invocation sample

Thank you.

Looks like it works but I've not finished my tests for now. I'll tell you when I'm done.

Twitter : @LaurentKP
My apps
Please use plain text.
Developer
laurentC
Posts: 266
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: Invocation sample

Thanks for the solution shaque. It works !
Twitter : @LaurentKP
My apps
Please use plain text.