Would you like to tell us how we are doing?

You bet No thanks

Creating Push-enabled Android apps

The push-enabled Android apps landing page image.

If your Android app uses Cloud to Device Messaging (C2DM) or Google Cloud Messaging (GCM), when you repackage your app for BlackBerry devices, you can use the push technology of the BlackBerry Application Platform to provide similar functionality. Push technology gives your users immediate access to content, without waiting for downloads.

The Google Play Services SDK is not supported on BlackBerry 10. If your app includes GCM services, you need to set up your project to the stand-alone GCM SDK.

To create a push-enabled Android app, you need to:

  • Register with the Push Service.
  • Create the configuration file.
  • Specify push as a required permission in the BAR file's manifest file.
  • In the push initiator, the server-side app used to send out pushes, format the data to be sent to BlackBerry Application servers instead of Google app servers.

Registering with the Push Service

Before you can register to launch your app, you must first register for evaluation.

Creating the android.cfg file

After you register with the Push Service, you must create a configuration file (the android.cfg file), which provides the BlackBerry Push configuration, and that allows your Android app to work without changing any code, or compiling again. Using any ZIP utility, add the android.cfg file to the BAR file. You should do this before you sign the BAR package.

When you register for a Push Service, you receive a registration ID unique to your device. Registration IDs from Google are in the form of APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx, and BlackBerry registration IDs contain 8 characters. To differentiate between BlackBerry and Android devices on the app server, you can prefix the registration ID with the token prefix in the android.cfg file.

When you registered for the Push Service, you received a PPG Base URL and an app ID. In the repackaged BAR file, create a file named android.cfg, and add the URL and app ID. Here's a sample android.cfg file:

<?xml version="1.0" encoding="utf-8"?> 
<android> 
   <push>
      <appid>some_appID</appid> 
      <ppgurl>http://cpXXX.pushapi.eval.blackberry.com</ppgurl> 
      <tokenprefix>bb-</tokenprefix>
   </push>
</android>

Here is a sample BAR file structure:

PushApp.bar/META-INFO/MANIFEST.MF
PushApp.bar/android/android.cfg 
PushApp.bar/android/PushApp.apk
PushApp.bar/android/res/drawable-hdpi/ic_launcher.png

Manifest permission

The Push Service requires that your signing keys have push capability enabled, and that push is specified as a required permission in the BAR file's manifest file. The required line is:

Entry-Point-System-Actions: _sys_use_consumer_push 

Server changes

With the C2DM and GCM services, the Google app servers sends push messages through a web request. BlackBerry Application Servers send push messages to BlackBerry devices through a similar web request. You must format your data before you send it to the Google app server. BlackBerry Push Service does not impose a format on the message. However, because the message is received by an Android app, you must format the data to the JSON format:

{ "key":"value", key2: value2, "key3": value3, key4 : "value 4" ... } 

Finally, your Push Initiator must send the data to BlackBerry Application Servers instead of Google app servers.

The Android Runtime will queue your pushes until the app is launched.



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus