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

Java Development

Reply
Regular Contributor
juszczec2
Posts: 59
Registered: ‎05-10-2012
My Device: 8800
My Carrier: verizon
Accepted Solution

maddening Push problem

[ Edited ]

Hello all

 

My app is running on a Curve and a Bold, OS v5.0.0.973/979.  I'm trying to register it to receive Push notifications and its failling.

 

I have the registration code running in its own thread, here's the run() method:

 

publicvoid run(){

 

ApplicationDescriptor ad = ApplicationDescriptor.currentApplicationDescriptor();

int port = Push Port from production registration email;

String appId = "ApplicationID from production registration email"

String bpasUrl = "PPG Base URL from production registration email";

 

 

byte serverType = PushApplicationDescriptor.SERVER_TYPE_BPAS;

 

PushApplicationDescriptor pad = new PushApplicationDescriptor(appId,

port, bpasUrl, serverType, ad);

 

PushApplicationStatus pushApplicationStatus = PushApplicationRegistry.getStatus(pad);

byte pasStatus = pushApplicationStatus.getStatus();

 

if (pasStatus == PushApplicationStatus.STATUS_ACTIVE) {

log("PUSH already registered");

} else if (pasStatus == PushApplicationStatus.STATUS_PENDING) {

log("PUSH registration PENDING");

} else {

try{

    PushApplicationRegistry.registerApplication(pad);

}

catch(IllegalArgumentException iae){

   log("error);

}

}

}

 

I've tried starting this Thread from 2 different places in my class which I've defined as:

 

public class MyApp extends UiApplication implements PushApplication

 

I've tried starting it from MyApp constructor and from a method after

enterEventDispatcher() is executed.

 

Is it required to do push registration in a separate Thread?  I've seen examples where push registration is done from within UiApplication and ones where its done in a different Thread.  Does it matter?

 

I understand I cannot post the actual values from the production registration email, but I've used the row labels from the email in the section titled:

 

       Application Credential (for use in your client application):

 

Am I using them in the right places in the registration code?

 

In addition, I've seen examples that use the PushApplicationReigstry methods as the example above does and I've also seen them actually using HttpConnection and InputStream/OutputStream.  Does it matter?

 

Control does make it back to MyApp and makes it to my onStatusChange() method defined as:

 

public void onStatusChange(PushApplicationStatus pushAppStatus) {

 

String message = null;

 

        byte bpsStatus = pushAppStatus.getStatus();

        byte regReason = pushAppStatus.getReason();

        String error = pushAppStatus.getError();

 

        boolean simChanged = false;

 

        String logStatus = "Unknown " + bpsStatus;

 

        switch( bpsStatus ) {

 

            case PushApplicationStatus.STATUS_ACTIVE:

 

         setPushRegistered(true);

         if( thread == null ) {

            thread = new MessageReadingThread();

            thread.start();

        }

        logStatus = "Active";

 

                break;

 

            case PushApplicationStatus.STATUS_FAILED:

 

                logStatus = "Failed";

 

                switch( pushAppStatus.getReason() ) {

                case PushApplicationStatus.REASON_SIM_CHANGE:

                 simChanged = true;

                 message = "Not registered due to SIM change";

                 break;

                case PushApplicationStatus.REASON_API_CALL:

      message = "Not registered due to API call?";

      break;

                case PushApplicationStatus.REASON_REJECTED_BY_SERVER:

                message = "Not registered due to rejection by server";

                break;

                case PushApplicationStatus.REASON_NETWORK_ERROR:

                message = "Not registered due to network error";

                break;

                case PushApplicationStatus.REASON_INVALID_PARAMETERS:

                message = "Not registered due to invalid parameters";

                break;

                }

                break;

 

            case PushApplicationStatus.STATUS_NOT_REGISTERED:

                logStatus = "Not Registered";

 

                switch( pushAppStatus.getReason() ) {

                case PushApplicationStatus.REASON_SIM_CHANGE:

                 simChanged = true;

                 message = "Not registered due to SIM change";

                 break;

                case PushApplicationStatus.REASON_API_CALL:

                message = "Not registered due to API call?";

                break;

                case PushApplicationStatus.REASON_REJECTED_BY_SERVER:

                message = "Not registered due to rejection by server";

                break;

                case PushApplicationStatus.REASON_NETWORK_ERROR:

                message = "Not registered due to network error";

                break;

                case PushApplicationStatus.REASON_INVALID_PARAMETERS:

                message = "Not registered due to invalid parameters";

                break;

                }

 

                break;

            case PushApplicationStatus.STATUS_PENDING:            

                logStatus = "Pending";

                break;

        }

 

        log(" message="+message);

 

}

 

I'm getting PushApplicationStatus.STATUS_FAILED.  

 

Is it reasonable to analyze pushAppStatus.getReason() at that point?  I've seen examples of code that doesn't examing pushAppStatus.getReason() when PushApplicationStatus.STATUS_FAILED is received.

 

If it is reasonable to call pushAppStatus.getReason() at this point, I got PushApplicationStatus.REASON_REJECTED_BY_SERVER

 

In addition, I believe I've seen examples of this code using using HttpConnection and InputStream/OutputStream.  Does that matter?

 

Is there a period of time after receipt of the production registration email before the values in the email are valid/accessible?

 

I've also read where where Push Registration can only be done via BIS thru the carrier network accessed via wifi.  Is there any truth to this?  Can Push Registration be done via BIS thru the local network accessed via wifi?

 

Help!

 

Mark

Please use plain text.
Regular Contributor
juszczec2
Posts: 59
Registered: ‎05-10-2012
My Device: 8800
My Carrier: verizon

Re: maddening Push problem

I got it fixed, but almost by accident.

 

I started wondering if I an HttpConnection based registration method would be more appropriate than the PushApplicationRegistry method I had been using.  At least half of the examples out there do not use PushApplicationRegistry.

 

So I started to reimplement my registration method based on PushAgent.java I found here:  http://supportforums.blackberry.com/t5/BlackBerry-Push-Development/Simplified-BIS-Push-client-sample...

 

I noticed it appended "mss/PD_subReg" to the url.  Since I had nothing to lose, I appended "mss/PD_subReg" to the url I received from RIM confirming the move of our app to production.  The was in a section called "Application Credentials (for use in your client application)" and was labelled "PPG Base URL**"

The ** is a footnote saying its for production use only.

Everything started to work just fine at that point.

 

I'm just curious, I spent a day combing thru documentation and couldn't find any references to this outside of the sample program at the link I posted.  Is there anywhere else I could have looked?

Please use plain text.
Developer
simon_hain
Posts: 16,023
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: maddening Push problem

I wrote the sample, and as far as i can remember i took the sources of the client code you get when you register and simplified that.
The RIM sample had an external logging factory and an own connection factory etc, i removed all that.
The connection logic was taken 1:1 from RIMs client sample, so i cannot explain why the "mss/PD_subReg" has to be added, i just copied it over.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Regular Contributor
juszczec2
Posts: 59
Registered: ‎05-10-2012
My Device: 8800
My Carrier: verizon

Re: maddening Push problem

Simon

 

Fair enough.  First THANK YOU for simplifying that example.  I've stared at RIMs example for a few hours and got nowhere, in addition to scouring the forums here.  The forums at least, showed it was a fairly common problem.

 

Hopefully, posting what worked for me will make someone else's life easier.

 

Mark

Please use plain text.
Developer
simon_hain
Posts: 16,023
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: maddening Push problem

yes, i felt the same, so i took the time to understand it and reduced it.
then i thought it would be simple to make a sample out of it and published it as a KB article, as i saw many questions about it.

don't hestitate to mark your post as solution to resolve this thread.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Regular Contributor
juszczec2
Posts: 59
Registered: ‎05-10-2012
My Device: 8800
My Carrier: verizon

Re: maddening Push problem

i've marked it.

 

that reminds me, i should do that to all the other threads i've made.

Please use plain text.