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

Web and WebWorks Development

Posts: 30
Registered: ‎09-19-2013
My Device: None
My Carrier: None

Receive push while app is closed

Hello. I know this question has been asked before but I have not found an answer. I have developed an app that receives push messages. This works as long as the app is open or has been closed for max 5 minutes. If it has been closed for 10 minutes or more the app stops receiving push messages.
Here is my code:
String httpUrl = "http://" + BesServer
+ ":" + BesPushPort
+ "/push" + destinations
+ "&PORT=" + "mytestapp"

var msg = "hello";
var httpWReq = (HttpWebRequest)WebRequest.Create(httpUrl);
httpWReq.Method = ("POST");
httpWReq.ContentType = "text/plain";
byte[] data = ASCIIEncoding.UTF8.GetBytes(msg);
if (data.Length <= 8192)
httpWReq.ContentLength = data.Length;
Stream requestStream = httpWReq.GetRequestStream();
requestStream.Write(data, 0, data.Length);
var httpWRes = (HttpWebResponse)httpWReq.GetResponse();
if (httpWRes.StatusCode == HttpStatusCode.OK)
//write success push

//write fail push


<widget xmlns:rim="http://www.blackberry.com/ns/widgets" version="" rim:header="RIM-Widget:rim/widget" xmlns="http://www.w3.org/ns/widgets" id="mytestapp">
<author >Magic</author>
<icon src="images/pushCaptureIcon.png" />
<content src="index.htm" />

<!-- Need to allow access to your externally accessible Push Initiator URL if using the Push Service SDK high-level APIs (with subscription support) -->
<!-- Replace "externally_accessible_Push_Initiator_URL" with your own domain name -->
<access uri="http://myserver:89" subdomains="true" />

<feature id="blackberry.app">
<param name="orientation" value="portrait" />
<feature id="blackberry.app" />
<feature id="blackberry.push" />
<feature id="blackberry.system" />
<feature id="blackberry.invoked" />
<feature id="blackberry.ui.dialog" />
<feature id="blackberry.ui.toast" />

<feature id="blackberry.identity" />
<feature id="blackberry.invoke" />

<rimSmiley Tongueermissions>
<rimSmiley Tongueermit>post_notification</rimSmiley Tongueermit>
<!-- This permission is needed for a consumer (public) push application only (not enterprise push)! -->
<!--<rimSmiley Tongueermit system="true">_sys_use_consumer_push</rimSmiley Tongueermit>-->
<rimSmiley Tongueermit>read_device_identifying_information</rimSmiley Tongueermit>
</rimSmiley Tongueermissions>

<!-- Need to put an invoke entry here for push -->
<!-- The id here must match the invokeTargetId passed in as one of the ops to blackberry.push.PushService.create -->
<rim:invoke-target id="mytestapp.invoke.push">

<!-- Have an invoke entry here for when a notification is clicked on in the BlackBerry Hub -->
<!-- This will cause the application to be opened -->
<rim:invoke-target id="mytestapp.invoke.open">

PushCapture.prototype.initPushService = function () {
if (blackberry.push) {
blackberry.event.addEventListener("invoked", sample.pushcapture.onInvoke);
if (blackberry.app.windowState == "fullscreen") {
sample.pushcapture.hasBeenInForeground = true;

blackberry.event.addEventListener("resume", sample.pushcapture.onResume);
PushCapture.prototype.createPushService = function () {
var ops = {
invokeTargetId: "mytestapp.invoke.push",
appId: "mytestapp"

.create(ops, sample.pushcapture.successCreatePushService, sample.pushcapture.failCreatePushService,
sample.pushcapture.onSimChange, sample.pushcapture.onPushTransportReady);

PushCapture.prototype.onInvoke = function (invokeRequest) {
if (invokeRequest.action != null && invokeRequest.action == "bb.action.PUSH") {
var pushPayload = sample.pushcapture.pushService.extractPushPayload(invokeRequest);
PushCapture.prototype.successCreatePushService = function (service) {
sample.pushcapture.pushService = service;

PushCapture.prototype.launchApplicationCallback = function (result) {
if (sample.pushcapture.pushService) {
PushCapture.prototype.createChannelCallback = function (result, token) {
sample.pushcapture.constructor.prototype.pushNotificationHandler = function (pushpayload) {
var contentType = pushpayload.headers["Content-Type"];
sample.pushcapture.processPush(pushpayload.data, contentType);
if (pushpayload.isAcknowledgeRequired) {
sample.pushcapture.constructor.prototype.processPush = function (content, contentType) {

In my index.htm header I have this code:
<script type="text/javascript">

function ready() {

/* Register our BlackBerry Push Service. */
// Create the push service (i.e. call create, etc.)


window.addEventListener("load", function (e) {
document.addEventListener("webworksready", ready);
}, false);


Posts: 30
Registered: ‎09-19-2013
My Device: None
My Carrier: None

Re: Receive push while app is closed

I guess this is the problem:



My app is installed in Workspace with password protection and It is not possible to receive push messages while Workspace is locked. The only solution so far is to write a native version instead :/ 

is this true?