SelectBlackBerry Configuration API Reference for Realtime Apps

 

This SDK has been deprecated.

If you have questions about the PubNub for BlackBerry SDK, please contact us at support@pubnub.com.

BlackBerry complete API reference for building Realtime Applications on PubNub, including basic usage and sample code.

  1. Open the Eclipse (Blackberry Java Plugin)
  2. Goto File -> New -> Blackberry Project
  3. Enter a project name ( for this example, we'll use PubnubExample ) and click Next
  4. Click "Link additional Source"
  5. Browse to and select java/blackberry/examples/PubnubExample/src and enter Folder name as src1
  6. Click "Finish"
  7. Select the Libraries tab
  8. Click "Add External JARs"
  9. Select bouncycastle.jar and Pubnub-Microedition-3.7.11.jar from libs
  10. Go to the "Order and Export" tab and check the boxes against bouncycastle.jar and Pubnub-Microedition-3.7.11.jar.
  11. Click "Finish"
  12. Create a Run Configuration by clicking Run -> Run Configurations from the menu
  13. Select Blackberry Simulator, right-click, and select New, you will now have access to some new tabs.
  14. Click the "Projects" tab
  15. Check the box against PubnubExample
  16. Click the "Simulator" tab, and confirm the Launch Mobile Data System Connection Service (MDS-CS) with simulator checkbox is selected
  17. Change the configuration name to PubnubExample
  18. Click "Apply"
  19. Right click PubnubExample in package explorer.
  20. Select Run As -> Blackberry Simulator. This will start MDS on command prompt and Blackberry Simulator
     
    NOTE: MDS may need to be manually started by running run.bat located at Eclipse\plugins\net.rim.ejde.componentpack7.1.0_7.1.0.10\components\MDS
  21. The MDS console will display debug information as the simulator phone boots.
  22. Once the simulator has booted, scroll to and select PubnubExample (it will have the default “App Window” icon)
  23. Run it, and select the menu button to see it run various PubNub for Blackberry API methods.
This function is used for initializing the PubNub Client API context. This function must be called before attempting to utilize any API functionality in order to establish account level credentials such as publish_key and subscribe_key.
To Initialize Pubnub you can use the following method(s) in the BlackBerry SDK:
  1. ParameterTypeRequiredDescription
    publish_keyStringYesSpecifies the required publish_key to be used only when publishing messages to achannel. This key can be specified at initialization or along with a publish() and need not be specified if the client will not publish data to any channel.
    subscribe_keyStringYesSpecifies the required subscribe_key to be used for subscribing to a channel.
  2. ParameterTypeRequiredDescription
    publish_keyStringYesSpecifies the required publish_key to be used only when publishing messages to a channel. This key can be specified at initialization or along with apublish() and need not be specified if the client will not publish data to any channel.
    subscribe_keyStringYesSpecifies the required subscribe_key to be used for subscribing to a channel.
    sslbooleanYesSetting a value of true enables transport layer encryption with SSL/TLS. Default is false.
  3. ParameterTypeRequiredDescription
    publish_keyStringYesSpecifies the required publish_key to be used only when publishing messages to achannel. This key can be specified at initialization or along with apublish() and need not be specified if the client will not publish data to any channel.
    subscribe_keyStringYesSpecifies the required subscribe_key to be used for subscribing to a channel.
    secret_keyStringYesSpecifies the secret key.
  4. ParameterTypeRequiredDescription
    publish_keyStringYesSpecifies the required publish_key to be used only when publishing messages to achannel. This key can be specified at initialization or along with apublish() and need not be specified if the client will not publish data to any channel.
    subscribe_keyStringYesSpecifies the required subscribe_key to be used for subscribing to a channel.
    secret_keyStringYesSpecifies the secret key.
    sslbooleanYesSetting a value of true enables transport layer encryption with SSL/TLS. Default is false.
  5. ParameterTypeRequiredDescription
    publish_keyStringYesSpecifies the required publish_key to be used only when publishing messages to achannel. This key can be specified at initialization or along with apublish() and need not be specified if the client will not publish data to any channel.
    subscribe_keyStringYesSpecifies the required subscribe_key to be used for subscribing to a channel.
    secret_keyStringYesSpecifies the secret key.
    cipher_keyStringYesSpecifies the cipher key.
    sslbooleanYesSetting a value of true enables transport layer encryption with SSL/TLS. Default is false.
  6. ParameterTypeRequiredDescription
    publish_keyStringYesSpecifies the required publish_key to be used only when publishing messages to achannel. This key can be specified at initialization or along with apublish() and need not be specified if the client will not publish data to any channel.
    subscribe_keyStringYesSpecifies the required subscribe_key to be used for subscribing to a channel.
    secret_keyStringYesSpecifies the secret key.
    cipher_keyStringYesSpecifies the cipher key.
    sslbooleanYesSetting a value of true enables transport layer encryption with SSL/TLS. Default is false.
    ivStringYesSpecifies the initialization vector
 Always set the UUID to uniquely identify the user or device that connects to PubNub. This UUID should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the UUID can significantly impact your billing if your account uses the Monthly Active Users (MAUs) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
Pubnub pubnub = new Pubnub("my_pubkey", "my_subkey", "", "", true);
It returns the Pubnub instance for invoking PubNub APIs like publish(), subscribe(), history(), here_now(), etc.
  1.  Always set the UUID to uniquely identify the user or device that connects to PubNub. This UUID should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the UUID can significantly impact your billing if your account uses the Monthly Active Users (MAUs) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
    Pubnub pubnub = new Pubnub("demo", "demo");
  2. In the case where a client will only read messages and never publish to a channel, you can simply omit the publish_key when initializing the client:
     Always set the UUID to uniquely identify the user or device that connects to PubNub. This UUID should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the UUID can significantly impact your billing if your account uses the Monthly Active Users (MAUs) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
    Pubnub pubnub = new Pubnub( "","demo");
  3. Set a custom UUID to identify your users.
     Always set the UUID to uniquely identify the user or device that connects to PubNub. This UUID should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the UUID can significantly impact your billing if your account uses the Monthly Active Users (MAUs) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
    Pubnub pubnub = new Pubnub("myPublishKey", "mySubscribeKey");
    String uuid = "myUniqueUUID";
    pubnub.setUUID(uuid);
  4. This examples demonstrates how to enable PubNub Transport Layer Encryption with SSL. Just initialize the client with ssl set to true. The hard work is done, now the PubNub API takes care of the rest. Just subscribe and publish as usual and you are good to go.

     Always set the UUID to uniquely identify the user or device that connects to PubNub. This UUID should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the UUID can significantly impact your billing if your account uses the Monthly Active Users (MAUs) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
    Pubnub pubnub = new Pubnub("my_pubkey", "my_subkey", "", "", true);
  5. Requires Access Manager add-on XRequires that the Access Manager add-on is enabled for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
     

    Anyone with the secret_key can grant and revoke permissions to your app. Never let your secret key be discovered, and to only exchange it / deliver it securely. Only use the secret_key on secure server-side platforms.

    When you init with secret_key, you get root permissions for the Access Manager. With this feature you don't have to grant access to your servers to access channel data. The servers get all access on all channels.

    For applications that will administer PAM permissions, the API is initialized with the secret_key as in the following example:
     Always set the UUID to uniquely identify the user or device that connects to PubNub. This UUID should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the UUID can significantly impact your billing if your account uses the Monthly Active Users (MAUs) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
    Pubnub pubnub = new Pubnub("", "my_subkey", "my_secretkey");
    Now that the pubnub object is instantiated the client will be able to access the PAM functions. The pubnub object will use the secret_key to sign all PAM messages to the PubNub Network.
These functions are used to set/get a user ID on the fly.
To set/get UUID you can use the following method(s) in BlackBerry SDK
  1. ParameterTypeRequiredDescription
    uuidStringYesnew UUID
  2. This method doesn't take any arguments.

  3. This function doesn't have any parameters.

 Always set the UUID to uniquely identify the user or device that connects to PubNub. This UUID should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the UUID can significantly impact your billing if your account uses the Monthly Active Users (MAUs) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
pubnub.setUUID("myUniqueUUID");
System.out.println(pubnub.getUUID());
System.out.println(pubnub.uuid());
  1. Get UUID Function returns current client uuid: uuid String
  2. Generate UUID return type is String. The output below demonstrates an example uuid that is returned:
    
    d73cc6e9-b433-4679-b730-e4e8536315ea
    
  1.  Always set the UUID to uniquely identify the user or device that connects to PubNub. This UUID should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the UUID can significantly impact your billing if your account uses the Monthly Active Users (MAUs) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
    Pubnub pubnub = new Pubnub("myPublishKey", "mySubscribeKey");
    pubnub.setUUID("myUniqueUUID");
  2. String channel = pubnub.uuid();
     
    pubnub.subscribe(channel, new Callback() {});
Setter and getter for users auth key.
  1. ParameterTypeRequiredDescription
    auth_keyStringYesAuth key
  2. This method doesn't take any arguments.
  3. The method doesn't take any arguments.
pubnub.setAuthKey("my_auth_key");
String auth_key = pubnub.getAuthKey();
pubnub.unsetAuthKey();
Get Auth key returns the current authentication key.
This default value is set to true, which means the last received time token will be used to retry subscribe and presence thus retrieving the messages missed during the disconnect. If the variable is set to false, retry subscribe and presence will use timetoken = 0.
  1. ParameterTypeRequiredDescription
    resumeOnReconnect
    boolean
    Yes

    If Resume on Reconnect is set to true, then Pubnub catches up on reconnection after disconnection.

    If false, then messages sent on the channel between disconnection and reconnection are not received.

    True or False setting for Resume on Reconnect

pubnub.setResumeOnReconnect(true);

Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
To set/get filters you can use the following methods.
  1. ParameterTypeRequiredDescription
    filterStringYesSpecifies the message filter to be used in subscribe
  2. returns the filter currently set.

 Always set the UUID to uniquely identify the user or device that connects to PubNub. This UUID should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the UUID can significantly impact your billing if your account uses the Monthly Active Users (MAUs) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
pubnub.setFilter("foo==\"bar\"");
String filter = pubnub.getFilter();
Get Filter Expression returns the Current filtering expression.