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
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10
Accepted Solution

Are your customers having Permission issues?

[ Edited ]

I've was experiencing customers turning of vital permissions by accident during the first installation.  So I have come up with a very simple solution and decided to share the code.

 

ApplicationUI.hpp

namespace system
    {
    	class InvokeManager;
    }
public:
      Q_INVOKABLE void permissions();
public slots:
      Q_INVOKABLE void processInvokeReply();

 ApplicationUI.cpp

#include <bb/system/InvokeRequest>
#include <bb/system/InvokeManager>
#include <bb/system/InvokeTargetReply>
using namespace bb::system;

setup a context property after opening your main.qml

QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    qml->setContextProperty("cpp", this); //used to call permissions() from qml

create the function

void ApplicationUI::permissions()
{
	InvokeRequest request;

	    // Setup the request properties according to the current configuration
	    request.setTarget(tr("sys.settings.target"));
	    request.setAction(tr("bb.action.OPEN"));
	    request.setMimeType(tr("settings/view"));
	    request.setUri(tr("settings://permissions"));

	    // Start the invocation
	    const InvokeReply *reply = m_invokeManager->invoke(request);
	    if (reply) {
	        // Ensure that processInvokeReply() is called when the invocation has finished
	        QObject::connect(reply, SIGNAL(finished()), this, SLOT(processInvokeReply()));
	    } else {
	        //m_errorMessage = tr("Invoke Failed! InvokeReply is empty.");
	        //emit errorMessageChanged();
	        return;
	    }
}

create a function to process the reply & delete the invocation so it can be used again later

void ApplicationUI::processInvokeReply() {
	InvokeReply *reply = qobject_cast<InvokeReply*>(sender());
	    // Delete the reply later on
	    reply->deleteLater();
}

 

In qml simply attach a call to run the function and you're all set

 

Container {
         horizontalAlignment: HorizontalAlignment.Fill
         Label {
              text: "Adjust Permissions"
              textStyle.base: SystemDefaults.TextStyles.BigText
              horizontalAlignment: HorizontalAlignment.Center
         }
         onTouch: {
              if (event.isUp()){
                   console.log("Adjsut Permissions")
                   cpp.permissions();
              }
         }
}

 Enjoy!

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

Re: Are your customers having Permission issues?

Forgot to mention you'll need to add to the .pro file

 

.pro

LIBS += -lbb -lbbsystem

 If you want to try it out in live action just download Spy Cam Extreme and scroll to the bottom of the help page =)