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
greenback
Posts: 533
Registered: ‎10-17-2010
My Device: (BlackBerry Z10)-> Q10/Passport Dual Use
Accepted Solution

Invoke Image Previewer or Photo editor Card Invocation.

What is the code to invoke the Image Previewer (in a card), or Photo Editor given the image location parameter?

C++ or QML.

 

Thank you!

Developer
bmorr
Posts: 331
Registered: ‎04-13-2013
My Device: Z10

Re: Invoke Image Previewer or Photo editor Card Invocation.

Here's the code I use for this:

 

void App::InvokeImageViewer(const QString &urlPic)
{
	bb::system::InvokeManager* manager = new InvokeManager();;
	bb::system::InvokeRequest request;

	// Setup what to show and in what target.
	request.setTarget("sys.pictures.card.previewer");
	request.setAction("bb.action.VIEW");
	request.setMimeType("image/jpg");
	request.setUri(urlPic);

	InvokeTargetReply *targetReply = manager->invoke(request);
}

 for further reference on invoking other apps look here: https://developer.blackberry.com/native/documentation/cascades/device_platform/invocation/invoking_c...

Developer
greenback
Posts: 533
Registered: ‎10-17-2010
My Device: (BlackBerry Z10)-> Q10/Passport Dual Use

Re: Invoke Image Previewer or Photo editor Card Invocation.

What code do I need to add to the main applicationui.cpp and applicationui.hpp files? To make this work?

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

Re: Invoke Image Previewer or Photo editor Card Invocation.

[ Edited ]

I've included the code I use to do this, the showphotoincard function has some additions that help prevent filepath errors.

 

You must add this line to your .pro file

 

LIBS += -lbbsystem

ApplicationUI.cpp

 

#include <bb/system/InvokeRequest>
#include <bb/system/InvokeManager>
#include <bb/system/InvokeTargetReply>

using namespace bb::cascades;
using namespace bb::system;

 

void ApplicationUI::showPhotoInCard(QString fileName)
{
    // Create InvokeManager and InvokeRequest objects to able to invoke a card with a viewer that will show the
    // latest bomber photo.
    bb::system::InvokeManager manager;
    InvokeRequest request;

    /*
     * WORKING URL SAMPLE: /accounts/1000/appdata/Your__Very_Long_Application_Identifier/app/native/assets/images/img.png
     */

    if (fileName.contains("file://")){
    	QString x = "file://";
    	fileName.remove(x);
    }
    // Setup what to show and in what target.
    request.setUri(QUrl::fromLocalFile(fileName));
    qDebug() << "ShowPIC: " << fileName;
    request.setTarget("sys.pictures.card.previewer");
    request.setAction("bb.action.VIEW");
    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);
    }
}

 

ApplicationUI.hpp

 

#define ApplicationUI_HPP_

using namespace bb::cascades;

namespace bb
{
    namespace cascades
    {
        class Application;
    }
    namespace system
    {
        class InvokeManager;
    }
}
//.... some other code
//ApplicationUI(bb::cascades::Application *app);
// virtual ~ApplicationUI() {}

//Add this line below ^the above line(s) in your .hpp file

Q_INVOKABLE void showPhotoInCard(QString fileName);

 Hope this helps!