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

BlackBerry Push Development

Reply
Developer
biggerCC
Posts: 270
Registered: ‎12-13-2010
My Device: PlayBook 16GB, BB10 Dev Alpha
Accepted Solution

Incoming Push invoking Browser

I've been playing with the pushCollector sample code. However I've stumbled across a weird problem.

Within the pushNotificationHandler function (app.cpp) I try to invoke the webbrowser (sample code below).

 

The code works fine, if the app is already started and in the foreground but does not work if the app is started from the push invocation itself.

 

    QString URL = "http://www.google.com";
	InvokeManager invokeManager;
	InvokeRequest request;
	request.setTarget("sys.browser");
	request.setAction("bb.action.OPEN");
	request.setMimeType("text/html");
	request.setUri(QUrl(URL));
	invokeManager.invoke(request);

Since this cannot be debugged easily (app needs to be closed first in order to reproduce), I'd like to know if anybody has a clue, what's going wrong here.

- - -
My approved apps @ App World
Retired
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Incoming Push invoking Browser

Hi,

 

Are you trying this on a Dev Alpha device or on a Z10?

 

Also, what OS version do you have running on the device?  The latest one (10.1.0.1485)?

 

I don't think we've tried that exact scenario, but I will pass it on to our testing team to give it a try and let you know the results.

 

Thanks,

 

Matt

Retired
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Incoming Push invoking Browser

Oh, wait a second, I just thought of something.

 

The default behaviour in the Push Collector sample is to process the push and, if the app has not been brought to the foreground, to exit.

 

See this section in the developer guide: http://developer.blackberry.com/cascades/documentation/device_comm/push/exiting_after_processing_pus...

 

You would have to disable that functionality if you want the app to remain open and perform an invoke to the browser.

 

Thanks,

 

Matt

Retired
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Incoming Push invoking Browser

Since you said the invoke is being done in your push processing code, could the app be exiting before it has finished the invoke of the browser?

 

Sorry for all the posts.  Just thinking of new things. :smileyhappy:

Developer
biggerCC
Posts: 270
Registered: ‎12-13-2010
My Device: PlayBook 16GB, BB10 Dev Alpha

Re: Incoming Push invoking Browser

[ Edited ]

Hey Matt,


I tried it using these two devices:

  • Z10, OS 10.0.10.90
  • DevAlpha C, OS 10.1.0.1485

Same result on both handsets: browser gets invocated only when the app is already running at forefront.

 

Of course I have been playing with (e.g. disabled) the forced exit:

if (!m_hasBeenInForeground) {
    	Application::instance()->requestExit();
    }

But my browser invocation is supposed to take place before these lines and commenting them out does still not solve my problem. It will show up in a minimized state, but still not launch the browser. The invocation really only works if my app was running up in front before the push happened, which is pretty weird...

- - -
My approved apps @ App World
Developer
biggerCC
Posts: 270
Registered: ‎12-13-2010
My Device: PlayBook 16GB, BB10 Dev Alpha

Re: Incoming Push invoking Browser

Here's the whole pushNotificationHandler function for passing to your testing guys:

 

void App::pushNotificationHandler(bb::network::PushPayload &pushPayload)
{
    PushHistoryItem pushHistoryItem(pushPayload.id());

    if (m_pushNotificationService.checkForDuplicatePush(pushHistoryItem)) {
        qWarning() << QString("Duplicate push was found with ID: %0.").arg(pushPayload.id());

        if (!m_hasBeenInForeground) {
        	Application::instance()->requestExit();
        }

        return;
    }

    Push push(pushPayload);

    push.setSeqNum(m_pushNotificationService.savePush(push));

    Notification *notification = new Notification(NOTIFICATION_PREFIX + QString::number(push.seqNum()),this);
    notification->setTitle("Chrome2BB");
    notification->setBody(QString("New push received"));

    InvokeRequest invokeRequest;
    invokeRequest.setTarget(INVOKE_TARGET_KEY_OPEN);
    invokeRequest.setAction(BB_OPEN_INVOCATION_ACTION);
    invokeRequest.setMimeType("text/plain");
    invokeRequest.setData(QByteArray::number(push.seqNum()));
    notification->setInvokeRequest(invokeRequest);
    notification->notify();

    QString URL = "http://www.google.com";
	InvokeManager invokeManager;
	InvokeRequest request;
	request.setTarget("sys.browser");
	request.setAction("bb.action.OPEN");
	request.setMimeType("text/html");
	request.setUri(QUrl(URL));
	invokeManager.invoke(request);

    m_model->insert(push.toMap());

    if (pushPayload.isAckRequired()) {
        m_pushNotificationService.acceptPush(pushPayload.id());
    }

    if (!m_hasBeenInForeground) {
    	Application::instance()->requestExit();
    }
}

 

- - -
My approved apps @ App World
Retired
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Incoming Push invoking Browser

Thanks!  We're looking into it.  I'll let you know what we find out.

Developer
biggerCC
Posts: 270
Registered: ‎12-13-2010
My Device: PlayBook 16GB, BB10 Dev Alpha

Re: Incoming Push invoking Browser

Actually I found a (quite hacky, but feasible) workaround: With:

 

#include <bps/navigator.h>

[...]

navigator_invoke("http://google.com", 0);

 

I get the results I was looking for, but I'm still interested in your findings, why the invocation framework fails!

- - -
My approved apps @ App World
Retired
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Incoming Push invoking Browser

Getting close to an answer for this.  Should have something for you tomorrow morning!

Retired
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Incoming Push invoking Browser

So, after talking with the invocation team, it appears that not being able to issue an invoke through an application running in the background is expected behaviour.

 

Here's the exact warning in the logs that I get when I tested it myself:

Warning - background application 'pushcapture.testRel_pushcaptureb8c6c6ec' not allowed to make invoke requests

 

The reasoning behind it is a user experience one.  Your application is running in the background, so it should not be allowed to invoke / launch another application to the foreground (such as the browser).

 

That being said, there is one possible option I can think of off the top of my head.  You could add a notification to the BlackBerry Hub and when the user opens your app and the push associated with it, launch the browser with the appropriate content.  I'm not quite sure if the URL you were trying to open in the browser is directly tied to your push though.  I'm just speculating.  Are they related somehow?

 

If you tell me your exact scenario, I might be able to think of other options as well.

 

Thanks,

 

Matt