List of all Iphone and Blackberry Development codes in a one click Iphone,objective C,xcode,blackberry Development,iOS Development

Tuesday, July 24, 2012

Push Notification in Blackberry

The BlackBerry Push Service is an essential component of the real-time, always-on experience of BlackBerry smartphones. It offers an efficient and reliable way of sending information to your users. It also lets your application process information in the background and notify users when their attention is required.

Refer this - developer.blackberry.com
First register for push Credentials.  (See the above link).
Use Alternate Entry Point Application. The Background app will listen for the push notifications. The UI Application is used to register the device for getting the push notification. You need to activate the BIS(Blackberry Internet Service) on your device.

Client app will be given upon requests (rincethomas33@gmail.com)

Client side code -

// Main Class-
class App extends UiApplication {
 private static App theApp;
  public App() {
       pushScreen(new register());    
    }

  public static void main(String[] args) {
          if (args.length > 0 && args[0].equals("push_msg") ){
             theApp = new App();
             theApp.enterEventDispatcher();   
       
            }
        else {      
            BackgroundApplication backApp=new BackgroundApplication();
            backApp.setupBackgroundApplication();
            backApp.enterEventDispatcher();
          
       }       
    }  
}

//Register Class-
public class register extends MainScreen{
    public register(){
    final ButtonField btn=new ButtonField("Register");
        add(btn);
     FieldChangeListener listener=new FieldChangeListener() {
                   public void fieldChanged(Field field, int context) {
                      
                       if(field==btn){
                          
                         registerBpas();
                          
                       }
                  
                   }};
        btn.setChangeListener(listener);
       
    }
}


public static void registerBpas() {

    new Thread() {
        public void run() {
            try {
                final String registerUrl = formRegisterRequest(BPAS_URL, APP_ID, null) + ";deviceside=false;ConnectionType=mds-public";
                System.out.println("\n\n\n msg registerBPAS URL is:  "+ registerUrl);
                HttpConnection httpConnection = (HttpConnection) Connector.open(registerUrl);
                InputStream is = httpConnection.openInputStream();
                String response = new String(IOUtilities.streamToBytes(is));
                System.out.println("\n\n\n\n\n\n msg RESPOSE CODE :    " + response);
                httpConnection.close();
                String nextUrl = formRegisterRequest(BPAS_URL, APP_ID, response) + ";deviceside=false;ConnectionType=mds-public";
                System.out.println("\n\n\n\n\n\n msg nextUrl :    " + nextUrl);
                HttpConnection nextHttpConnection = (HttpConnection) Connector.open(nextUrl);
                InputStream nextInputStream = nextHttpConnection.openInputStream();
                response = new String(IOUtilities.streamToBytes(nextInputStream));
                System.out.println("\n\n\n\n\n\n msg RESPOSE CODE 1:    " + response);
                nextHttpConnection.close();
                if (REGISTER_SUCCESSFUL.equals(response) || USER_ALREADY_SUBSCRIBED.equals(response)) {
                    Dialog.alert("msg Registered successfully for BIS push");
                   
                   
                    System.out.println("msg Registered successfully for BIS push");
                } else {
                    Dialog.alert("msg BPAS rejected registration");
                    System.out.println("msg BPAS rejected registration");
                }
            } catch (final IOException e) {
                Dialog.alert("msg IOException on register() " + e + " " + e.getMessage());
                System.out.println("msg IOException on register() " + e + " " + e.getMessage());
            }
        }
    }.start();
}

private static String formRegisterRequest(String bpasUrl, String appId, String token) {
    StringBuffer sb = new StringBuffer(bpasUrl);
    sb.append("/mss/PD_subReg?");
    sb.append("serviceid=").append(appId);
    sb.append("&osversion=").append(DeviceInfo.getSoftwareVersion());
    sb.append("&model=").append(DeviceInfo.getDeviceName());
    if (token != null && token.length() > 0) {
        sb.append("&").append(token);
    }
    return sb.toString();
}
}

public static void close(Connection conn, InputStream is, OutputStream os) {
    if (os != null) {
        try {
            os.close();
        } catch (IOException e) {
        }
    }
    if (is != null) {
        try {
            is.close();
        } catch (IOException e) {
        }
    }
    if (conn != null) {
        try {
            conn.close();
        } catch (IOException e) {
        }
    }
}

//Background listener class

class BackgroundApplication extends Application {  
   
    public BackgroundApplication() {
        // TODO Auto-generated constructor stub
    }
    public void setupBackgroundApplication(){
       
        MessageReadingThread messageReadingThread = new MessageReadingThread();
        messageReadingThread.start();
       
    }  
   
    private static class MessageReadingThread extends Thread { private boolean running;
        private ServerSocketConnection socket;
        private HttpServerConnection conn;
        private InputStream inputStream;
        private PushInputStream pushInputStream;

        public MessageReadingThread() {
            this.running = true;
        }

        public void run() {
           
             String url = "http://:" + Port;
             url += ";deviceside=false;ConnectionType=mds-public";
             if ((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) && RadioInfo.areWAFsSupported(RadioInfo.WAF_WLAN)) {
                 url += ";interface=wifi";
                 }
           
            try {
                socket = (ServerSocketConnection) Connector.open( url );
            } catch( IOException ex ) {
                // can't open the port, probably taken by another application
                onListenError( ex );
            }

            while( running ) {
                try {
                    Object o = socket.acceptAndOpen();
                    conn = (HttpServerConnection) o;
                    inputStream = conn.openInputStream();
                    pushInputStream = new MDSPushInputStream( conn, inputStream );
                    PushMessageReader.process( pushInputStream, conn );
                } catch( Exception e ) {
                    if( running ) {
                      //  Logger.warn( "Failed to read push message, caused by " + e.getMessage() );
                        running = false;
                    }
                } finally {
                   // PushUtils.close( conn, pushInputStream, null );
                }
            }

          //  Logger.log( "Stopped listening for push messages" );
        }

        public void stopRunning() {
            running = false;
            //PushUtils.close( socket, null, null );
        }

        private void onListenError( final Exception ex ) {
           // Logger.warn( "Failed to open port, caused by " + ex );
          System.out.println(ex);
        }
    }
   
}
//push message reader class -

// HTTP header property that carries unique push message ID
    private static final String MESSAGE_ID_HEADER = "Push-Message-ID";
    // content type constant for text messages
    private static final String MESSAGE_TYPE_TEXT = "text";
    private static final int MESSAGE_ID_HISTORY_LENGTH = 10;
    private static String[] messageIdHistory = new String[MESSAGE_ID_HISTORY_LENGTH];
    private static byte historyIndex;

    private static byte[] buffer = new byte[15 * 1024];
public static void process(PushInputStream pis, Connection conn) {
        System.out.println("Reading incoming push message ...");

        try {

            HttpServerConnection httpConn;
            if (conn instanceof HttpServerConnection) {
                httpConn = (HttpServerConnection) conn;
            } else {
                throw new IllegalArgumentException("Can not process non-http pushes, expected HttpServerConnection but have "
                        + conn.getClass().getName());
            }

            String msgId = httpConn.getHeaderField(MESSAGE_ID_HEADER);
            String msgType = httpConn.getType();
            String encoding = httpConn.getEncoding();

            System.out.println("Message props: ID=" + msgId + ", Type=" + msgType + ", Encoding=" + encoding);

           
            boolean accept = true;
            if (!alreadyReceived(msgId)) {
                byte[] binaryData;

                if (msgId == null) {
                    msgId = String.valueOf(System.currentTimeMillis());
                }

                if (msgType == null) {
                    System.out.println("Message content type is NULL");
                    accept = false;
                } else if (msgType.indexOf(MESSAGE_TYPE_TEXT) >= 0) {
                    // a string
                    int size = pis.read(buffer);
                    binaryData = new byte[size];
                    System.arraycopy(buffer, 0, binaryData, 0, size);   
                   
                    PushMessage message = new PushMessage(msgId, System.currentTimeMillis(), binaryData, true, true );
                    String text = new String( message.getData(), "UTF-8" );
                     try{
                            final Dialog screen = new Dialog(Dialog.D_OK_CANCEL, " "+text,
                                    Dialog.OK,
                                    //mImageGreen.getBitmap(),
                                    null, Manager.VERTICAL_SCROLL);
                            final UiEngine ui = Ui.getUiEngine();
                            Application.getApplication().invokeAndWait(new Runnable() {
                                public void run() {
                                    NotificationsManager.triggerImmediateEvent(0x749cb23a76c66e2dL, 0, null, null);
                                    ui.pushGlobalScreen(screen, 0, UiEngine.GLOBAL_QUEUE);
                                   
                                }
                            });
                            screen.setDialogClosedListener(new MyDialogClosedListener());
                            }
                            catch (Exception e) {
                                // TODO: handle exception
                            }
                           
                   
                    // TODO report message
                }  else {
                    System.out.println("Unknown message type " + msgType);
                    accept = false;
                }
            } else {
                System.out.println("Received duplicate message with ID " + msgId);
            }
            pis.accept();
        } catch (Exception e) {
            System.out.println("Failed to process push message: " + e);
        }
    }



private static boolean alreadyReceived(String id) {
        if (id == null) {
            return false;
        }

        if (Arrays.contains(messageIdHistory, id)) {
            return true;
        }

        // new ID, append to the history (oldest element will be eliminated)
        messageIdHistory[historyIndex++] = id;
        if (historyIndex >= MESSAGE_ID_HISTORY_LENGTH) {
            historyIndex = 0;
        }
        return false;
    }



public class PushMessage{

    private String id;
    private long timestamp;
    private byte[] data;
    private boolean textMesasge;
    private boolean unread;

    public PushMessage( String id, long timestamp, byte[] data, boolean textMesasge, boolean unread ) {
        super();
        this.id = id;
        this.timestamp = timestamp;
        this.data = data;
        this.textMesasge = textMesasge;
        this.unread = unread;
    }

    public String getId() {
        return id;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public byte[] getData() {
        return data;
    }

    public boolean isTextMesasge() {
        return textMesasge;
    }

    public boolean isUnread() {
        return unread;
    }

    public void setUnread( boolean unread ) {
        this.unread = unread;
    }

}

public class MyDialogClosedListener implements DialogClosedListener
    {

    public void dialogClosed(Dialog dialog, int choice)
    {
        if(dialog.equals(dialog))
        {
           if(choice == -1)
            {
                //Your code for Press OK
            }
            if(choice == 1)
            {
                //Your code for Press Cancel
               
            }
                   }
   }
}

For setting alternate entry point - Refer below images -


Server sode PHP code is given Below -

//
ini_set('display_errors','1');
error_reporting(E_ALL);

    // APP ID provided by RIM
$appid = 'app id';
// Password provided by RIM
$password = 'password';
//Deliver before timestamp
$deliverbefore = gmdate('Y-m-d\TH:i:s\Z', strtotime('+time minutes'));

//An array of address must be in PIN format or "push_all"
$addresstosendto[] = 'your pin';

$addresses = '';
foreach ($addresstosendto as $value) {
$addresses .= '
';
}

// create a new cURL resource
$err = false;
$ch = curl_init();
$messageid = microtime(true);

$data = '--mPsbVQo0a68eIL3OAxnm'. "\r\n" .
'Content-Type: application/xml; charset=UTF-8' . "\r\n\r\n" .
'
'
. $addresses .
'
' . "\r\n" .
'--mPsbVQo0a68eIL3OAxnm' . "\r\n" .
'Content-Type: text/plain' . "\r\n" .
'Push-Message-ID: ' . $messageid . "\r\n\r\n" .
stripslashes('r') . "\r\n" .
'--mPsbVQo0a68eIL3OAxnm--' . "\n\r";

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://pushapi.eval.blackberry.com/mss/PD_pushRequest");//"https://cp2991.pushapi.eval.blackberry.com/mss/PD_pushRequest"
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, "Hallgren Networks BB Push Server/1.0");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $appid . ':' . $password);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/related; boundary=mPsbVQo0a68eIL3OAxnm; type=application/xml", "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2", "Connection: keep-alive"));

// grab URL and pass it to the browser
echo $xmldata = curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

//Start parsing response into XML data that we can read and output
$p = xml_parser_create();
xml_parse_into_struct($p, $xmldata, $vals);
$errorcode = xml_get_error_code($p);
if ($errorcode > 0) {
echo xml_error_string($errorcode);
$err = true;
}
xml_parser_free($p);

echo 'Our PUSH-ID: ' . $messageid . "
\n";
if (!$err && $vals[1]['tag'] == 'PUSH-RESPONSE') {
echo 'PUSH-ID: ' . $vals[1]['attributes']['PUSH-ID'] . "
\n";
echo 'REPLY-TIME: ' . $vals[1]['attributes']['REPLY-TIME'] . "
\n";
echo 'Response CODE: ' . $vals[2]['attributes']['CODE'] . "
\n";
echo 'Response DESC: ' . $vals[2]['attributes']['DESC'] . "
\n";
} else {
echo 'An error has occured
' . "\n";
echo 'Error CODE: ' . $vals[1]['attributes']['CODE'] . "
\n";
echo 'Error DESC: ' . $vals[1]['attributes']['DESC'] . "
\n";
}

?>



OR Server sode C# code is given Below -

private void pushMessageSample(string pushedMessage)
    {
        String appid="xxxx-xxxxxxxxxxxxxxxxxxxxxxxxxx";
        String password = "xxxxxx";
        String deliverbefore = DateTime.UtcNow.AddMinutes(5).ToString("s",System.Globalization.CultureInfo.InvariantCulture) + "Z";
        String pushPin = "xxxxxxxx";
        String Boundary = "mPsbVQo0a68eIL3OAxnm";

 StringBuilder dataToSend = new StringBuilder();

 dataToSend.AppendLine("--" + Boundary);
 dataToSend.AppendLine("Content-Type: application/xml; charset=UTF-8");

 dataToSend.AppendLine("");
 dataToSend.AppendLine("");
 dataToSend.AppendLine("");
 dataToSend.AppendLine("");
 string myPushId = DateTime.Now.ToFileTime().ToString();
 dataToSend.AppendLine("");
 //dataToSend.AppendLine("");
 dataToSend.AppendLine("

");
 dataToSend.AppendLine("");
 dataToSend.AppendLine("
");
 dataToSend.AppendLine("");
 dataToSend.AppendLine("--" + Boundary);

 dataToSend.AppendLine("Content-Type: text/plain");
 dataToSend.AppendLine("Push-Message-ID: " + myPushId);
 dataToSend.AppendLine("");

 dataToSend.AppendLine(pushedMessage);

 dataToSend.AppendLine("--" + Boundary + "--");
 dataToSend.AppendLine("");

 byte[] bytes = Encoding.ASCII.GetBytes(dataToSend.ToString());
        String httpURL = "https://cpxxxx.pushapi.eval.blackberry.com/mss/PD_pushRequest";

            WebRequest tRequest;
            tRequest = WebRequest.Create(httpURL);
            //SetProxy(tRequest);
            tRequest.Method = "POST";
            //tRequest.ContentType = "text/plain";

            //tRequest.ContentLength = bytes.Length;
            tRequest.Credentials = new NetworkCredential(appid, password);

            tRequest.PreAuthenticate = true;
            tRequest.ContentType = "multipart/related; boundary=" + Boundary + "; type=application/xml";
            tRequest.ContentLength = bytes.Length;
            string rawCredentials = string.Format("{0}:{1}", appid, password);
            tRequest.Headers.Add("Authorization",
                string.Format(
                    "Basic {0}",
                    Convert.ToBase64String(Encoding.UTF8.GetBytes(rawCredentials))));

            SetBasicAuthHeader(tRequest, appid, password);

            Stream dataStream = tRequest.GetRequestStream();
            dataStream.Write(bytes, 0, bytes.Length);
            dataStream.Close();

            WebResponse tResponse = tRequest.GetResponse();

            dataStream = tResponse.GetResponseStream();

            StreamReader tReader = new StreamReader(dataStream);

            String sResponseFromServer = tReader.ReadToEnd();

            tReader.Close();
            dataStream.Close();
            tResponse.Close();
    }

public static void SetBasicAuthHeader(WebRequest req, String appID, String userPassword)
    {
        string authInfo = appID + ":" + userPassword;
        authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
        req.Headers["Authorization"] = "Basic " + authInfo;
    }






        

60 comments:

  1. Very nice blog .....provided me gr8 support....Gr8 work Rince.....:-)

    ReplyDelete
  2. You have made some very astute statements and I appreciate the effort you have put into your writing. It's clear that you know what you are writing about. I am excited to read more of your sites content.

    I really love using best push notification through my Blackberry phone.

    ReplyDelete
  3. hello sir, should i place that entire code on file *java file? may i have the complete project source, please. i'm new to bb developemnt

    ReplyDelete
    Replies
    1. not in a single file. You have to create separate files for this.

      Delete
  4. thankks for your answer sir, i have tried but it seems never got subscribed.

    i try to running the client side from emulator. should i run from real device to subscribe or i can run it from emulator?

    and for server side, can i deploy it on localhost or should i have public IP?

    thank you

    ReplyDelete
    Replies
    1. for subscribing push, you need a real device with BIS connection. Push message will not works on Simulators.

      Delete
  5. i have compiled the client side code and installed it. when i tried to run, its doesnt respons. the application is not running, no gui appears... please help me sir

    ReplyDelete
  6. very very thank you.. i will try it now..

    ReplyDelete
  7. sir, which var for receiving push string?
    i want to display the push message as pop up. how to do that?

    thank you sir for your hellp

    ReplyDelete
  8. i dont understand this part

    if (args.length > 0 && args[0].equals("BB_push") ){
    theApp = new App();
    theApp.enterEventDispatcher();

    }
    else {
    BackgroundApplication backApp=new BackgroundApplication();
    backApp.setupBackgroundApplication();
    backApp.enterEventDispatcher();

    }

    how if i want to still showing main screen for the second run? can i change it to something like this

    if (args != null && args.length > 0 && args[0].equals("gui")){

    push_main.registerBpas();
    BackgroundApplication backApp=new BackgroundApplication();
    backApp.setupBackgroundApplication();

    MainApp app = new MainApp();
    app.enterEventDispatcher();


    } else {
    System.exit(0);
    }

    ReplyDelete
  9. Artikel, you just run the demo app, it will display alert.
    String text = new String( message.getData(), "UTF-8" );
    this will fetch the string.

    ReplyDelete
  10. that part is for running ui and background app. No you cant change it. if you change, it will not works.

    ReplyDelete
    Replies
    1. but if still used your code

      if (args.length > 0 && args[0].equals("push_msg") ){
      theApp = new App();
      theApp.enterEventDispatcher();

      }
      else {
      BackgroundApplication backApp=new BackgroundApplication();
      backApp.setupBackgroundApplication();
      backApp.enterEventDispatcher();

      }

      my application is only run once time at the first time.when i close it and try to run it again, its showing nothing sir, no gui appers.

      i want my application still showing GUI when its run for second time.

      Delete
    2. did you set "push_msg" as alternate entry point ?

      Delete
  11. i have used this example and getting the following exception
    msg IOException on register() net.rim.device.cldc.io.ippp.SocketBaseIOException: Connection reset by peer Connection reset by peer

    ReplyDelete
    Replies
    1. BIS is active on your device ?. In simulators, it will not work.

      Delete
    2. yes, i have BIS activate on my device

      Delete
    3. what's goin on if my BIS is not active?it will give us an error or just a message?

      Delete
  12. when i run this code i'm getting following exception
    msg IOException on register() net.rim.device.cldc.io.ippp.SocketBaseIOException: Connection reset by[0.0] peer Connection reset by peer

    ReplyDelete
  13. hi, i have implement push notification.., the code is working fine i'm recieving push notification and i have created my own pop up screen for displaying the push mesg,,,but app is crashing

    look at the push message reader class - where i'm getting the msg in dilaog box ..
    Application.getApplication().invokeAndWait(new Runnable() {
    public void run() {
    NotificationsManager.triggerImmediateEvent(0x749cb23a76c66e2dL, 0, null, null);
    ui.pushGlobalScreen(screen, 0, UiEngine.GLOBAL_QUEUE);

    }
    });
    and instead of showing in default dialog , i have created my pop up screen ..,to show the msg but that was giving me error , as i posted in my ist post, here is my code in PushMessageReader class, plz guide me
    Application.getApplication().invokeAndWait(new Runnable() {

    public void run() {

    //NotificationsManager.triggerImmediateEvent(0x749cb23a76c66e2dL, 0, null, null);
    ShowPushNotification shownotification = new ShowPushNotification();;
    final UiEngine ui = Ui.getUiEngine();
    ui.pushGlobalScreen(new ShowPushNotification(), 0, UiEngine.GLOBAL_QUEUE);

    }
    });

    class ShowPushNotification extends PopupScreen{

    LabelField mesglabel = new LabelField();
    ButtonField okbtn = new ButtonField("Ok", ButtonField.USE_ALL_WIDTH | DrawStyle.HCENTER);

    public ShowPushNotification(){
    super(new VerticalFieldManager(), Screen.DEFAULT_CLOSE);
    System.out.println("ShowPushNotification===================");
    //this.setBackground(BackgroundFactory.createSolidTransparentBackground(Color.WHITE, 80));

    setBorder(BorderFactory.createSimpleBorder(new XYEdges(),Border.STYLE_TRANSPARENT));

    LabelField lbl = new LabelField("SUNRAYS", LabelField.USE_ALL_WIDTH | DrawStyle.HCENTER){
    protected void paintBackground(net.rim.device.api.ui.Graphics g)
    {
    g.clear();
    g.getColor();
    g.setColor(Color.WHITESMOKE);
    g.fillRect(0, 0, Display.getWidth(), Display.getHeight());
    g.setColor(Color.BLACK);

    }

    };

    this.add(lbl);
    this.add(mesglabel);

    mesglabel.setText(text);
    //UiApplication.getUiApplication().popScreen(screen);
    okbtn.setChangeListener(new FieldChangeListener() {

    public void fieldChanged(Field field, int context) {
    // TODO Auto-generated method stub
    close();
    }
    });

    }

    }

    ReplyDelete
    Replies
    1. First open the uiapplication.Then push your screen.
      ApplicationDescriptor[] appDescriptors=CodeModuleManager.getApplicationDescriptors(CodeModuleManager.getModuleHandle("push_msg"));
      ApplicationDescriptor appDescriptor = new ApplicationDescriptor(appDescriptors[0], new String[]{"push_msg"});
      ApplicationManager.getApplicationManager().runApplication(appDescriptor);

      then push your Screen ShowPushNotification.

      Delete
    2. ApplicationDescriptor[] appDescriptors =CodeModuleManager.getApplicationDescriptors(CodeModuleManager.getModuleHandle("‌​push_msg")); ApplicationDescriptor appDescriptor = new ApplicationDescriptor(appDescriptors[0], new String[] {"push_msg"}); ApplicationManager.getApplicationManager().runApplication(appDescriptor); This will open your application. then you can push your popup screen. 1 Drawback- everytime when u get new message,it will open up app and push screen.

      Delete
    3. and one thing you have told me that, the default popup dialog is global popup. it'll show even if our app is in background or in foreground and plz can you explain me that why can not we use that concept with our own Pop up screen to show msg even if our app is in background or in foreground

      Delete
  14. thank you sir, your code working great

    ReplyDelete
  15. Hi RT,

    I need to create a push service in c#.
    I just get registered myself at https://www.blackberry.com/profile/?eventId=8121
    but, it says it will take a week to get registered.

    Can you provide me the test credentials, so we can test the service?

    Thank You.


    ReplyDelete
    Replies
    1. within 2 days you will get the credentials. 7 Days are the maxximum days. You can expect within 2 days. Depending upon BB.

      Delete
  16. hi, my credentials are expired for push so email for new one and after using new one i'm getting the following error msg RESPOSE CODE 1: rc=10002 [0.0] FD Back On [0.0] msg BPAS rejected registration –

    ReplyDelete
  17. hi.., i have used your code in my app.., but i want to ask you that the push notification will arrive even our app is closed
    is it Drain the phone's battery ., plz reply , it's urgent

    ReplyDelete
    Replies
    1. you will get the notification if your app is closed. The message listener class extends application. so you will get the notifications.

      Delete
    2. but.., is it cause battery drain in my app ?

      Delete
    3. yes it will. But not too much drain.

      Delete
    4. hi, so it will drain my battery little bit
      and can i perform ON and OFF functionality within your code for push notification for eg- i have object choice filed having two options On and Off when i select off from object choice filed the push notification will be disable and when i click to On from object choice field the push notification will be enabled

      Delete
  18. Hello,

    I am using blackberry java SDK 7.1.0 i have implement your code in my application i can't register all time return :
    "msg BPAS rejected registration"
    i have change the connection string and the app id and the port many time and still same error .
    Thanks in advance.

    ReplyDelete
    Replies
    1. you changed the registration url ?. Dont change the url.

      Delete
    2. i am using this url :
      String BPAS_URL="http://cp4159.pushapi.eval.blackberry.com";

      Delete
    3. After calling :


      HttpConnection httpConnection = (HttpConnection) Connector.open(registerUrl);
      InputStream is = httpConnection.openInputStream();
      String response = new String(IOUtilities.streamToBytes(is));
      System.out.println("\n\n\n\n\n\n msg RESPOSE CODE : " + response);
      httpConnection.close();

      the response is "< HTML >< /HTML >" only .

      Delete
    4. Change String BPAS_URL="http://cp4159.pushapi.eval.blackberry.com"; to
      BPAS_URL="http://pushapi.eval.blackberry.com";

      Delete
    5. Thanks a lot for your reply,

      It work well for me now , only i have to change the plan that i use i was using 3G plan that does not include
      BIS(Blackberry Internet Service).

      Delete
    6. at last you find the solution :P....
      BIS is mandatory for getting push messages...

      Delete
  19. hi, so it will drain my battery little bit
    and can i perform ON and OFF functionality within your code for push notification for eg- i have object choice filed having two options On and Off when i select off from object choice filed the push notification will be disable and when i click to On from object choice field the push notification will be enabled

    ReplyDelete
    Replies
    1. it will drain your battery little bit.
      You can perform on and off functionality. If you off it, you unregister for push notification and if you click on, then register for it.

      Delete
    2. thanks for reply, i got your point but which code should i used to unregister the push notification

      Delete
  20. thanks for your reply, and I got your point , please can you suggest me which CODE should i use to unregister the push notification , I have searched alot but not able to find any help

    ReplyDelete
  21. Hi.. I have implement this code. registration is work fine but push message is not getting.
    Server side getting 1001 response code..

    ReplyDelete
  22. this is a working code. its live in one of my app. Make sure that BIS is active and check the time difference between your server and your local time. Add that difference in server code so the push message will reach u at proper time.

    ReplyDelete
  23. Hi Rince, Thanks a ton for the reply..
    Yes the BIS service is active on the device and we are having a inhouse server which having the same local time ... in IST (Indian Standard time).

    On triggering the request from server the response is 1001
    But on Device side with the given code running over it in background, i dont get any push message.

    I have tested the app on simulator also to check for background listner activity... which is working.
    ....Let me know your email ID where i can share the code with you.

    I being trying for past 2 weeks over push notifications, and tried urban airship also... but there my device token is not getting registered.

    Looking forward to hear back from you.


    Thanks in advance!


    ReplyDelete
    Replies
    1. Thanks to replying. brainvire.technology@gmail.com this is id.

      Delete
  24. HI Rince,
    I tried mailing you the code but the mail was not sent by any of mail ids.
    So can you please download it from https://www.dropbox.com/s/n5mbi38rm9qof36/blackberry%20App%20Sample%20code.zip
    i have attached the client and server side code in it .

    i had the BIS service active on the device and we are having a in-house server which having the same local time ... in IST (Indian Standard time).

    On triggering the request from server the response is 1001
    But on Device side with the given code running over it in background, I don't get any push message.

    ON the client Application side With Register i was also getting the response code rc=200, meaning the device PIN is registered with RIM.

    I have tested the app on simulator also to check for background listener activity... which is working.

    Looking forward to the best possible help from your side.

    Thanks

    ReplyDelete
  25. Hi Rince,
    I tried Mailing you but the mail was bouncing back.
    Please download the sample app code along with the C# code i am using at my end for PUSH.

    https://www.dropbox.com/s/n5mbi38rm9qof36/blackberry%20App%20Sample%20code.zip

    i had the BIS service active on the device and we are having a in-house server which having the same local time ... in IST (Indian Standard time).

    On triggering the request from server the response is 1001
    But on Device side with the given code running over it in background, I don't get any push message.

    ON the client Application side With Register i was also getting the response code rc=200, meaning the device PIN is registered with RIM.

    I have tested the app on simulator also to check for background listener activity... which is working.

    Looking forward to the best possible help from your side.

    Thanks

    ReplyDelete
  26. Hi Rince,

    I like to take this opportunity to thank and appreciate the time and effort you have invested in helping me out with the push notification module.
    Only a developer can understand the pain of other developer.
    As a tribute i have added you name in the source code of the app i am developing.

    Thanks a ton again!
    Cheers!!

    ReplyDelete
  27. Hi,

    Thanks a lot first. But I am not clear about secondary entry point.
    I have created secondary entry point, and so in my device/simulator it shoes 2 icons.
    One for the app, and other for push_msg
    When I clicks on actual app nothing happens not UI and no action, app only opens when I click on icon of push_msg..
    Which i can understand from the code (if (args.length > 0 && args[0].equals("push_msg") ){}).

    So how to prevent displaying 2 icons on the device? and open app when user clicks on actual app icon instead of push_msg icon..

    Thanks.
    I hope you will help me regarding this.

    ReplyDelete