B4J Tutorial Creating push-enabled android-apps on blackberry

I would like to share my experience with creating push-enabled android-apps for blackberry-devices. Many thanks to Erel, who supports my efforts decisively.

I have tried a lot of things to enable the google play-services on blackberry-devices for using the GCM, but I was not able to register a device for google push. The only way to push an android-app on a blackberry-device is to use the blackberry-push service. In the following steps, I made my messenger-app blackberry-compatible. While using the apps only in our company, I don’t know, if these apps are accepted by the blackberry-world. I didn’t tested it.


First, you have to order a blackberry key for developer here:

Fill out the personal information and click also on

“For Blackberry 10 apps developed using Blackberry 10 SDK 10.2 or higher……”

Note, that your Email-address in the personal information must be the same as the address in the second step for the blackberry push-account!

After that, you have to create an account to the blackberry push service. There are two types of accounts:

An account for a test environment:

And an account for using your app in production:

I used the first link for testing. In the application description, I wrote 4 or 5 sentences and the push type I chooses was “Blackberry Push Essentials”. The different to “Push Plus” is, that there is no status request and it is a free service.

After that, you will get a mail from Blackberry with a csk-file, which is the your developer Blackberry-ID and a mail with your private push credentials. The ID is valid for one year. It could take up to 5 days until you get the mail with your push credentials.

Now, we make our android-push app valid for registration to the blackberry-push service. The construction of the push-enabled android-app and the server-side is the same as:

It is no need to change the code of a push-enabled android-app. Everything could be done from “outside”. It is only necessary to later adjust the server-code.

We now have to generate a simple android.cfg with a simple text editor:

<?xml version="1.0" encoding="utf-8"?> <android>

Copy the text into the editor and set your private credentials of the blackberry-email (Client Configuration).

You can change the token prefix in every string you want or you could set nothing. The token prefix will preceding to the device token after registration the device to the blackberry push service. Every blackberry-token is only eight characters long. So you can differentiate a returning token between android (for example: APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx) and a blackberry token (for example: 31D54A54) with the token length or you use the prefix like I do. For example bb:31D54A54

Save the file under android.cfg.

Now you need to download the Android Studio Plugin:

We need the Blackberry APK Packager to configure the android-apk-file. Start Blackberry APK Packager and configure the packager like I did:


After pressing “Package”, you need to set the “Autor-Detect”. Here, you have to choose the csk-file, which was send to you in one of the blackberry emails. Note, that you have to confirm the file with your password.

In some descriptions out of the internet, there is told, that it is necessary to configure the manifest-file to enable the blackberry device for push mails. I’m using a Blackberry Leap with OS 10.3 and there is no need to configure the manifest. You could let the manifest-file be as under android.

After that, we have the ready and signed BAR-File, which is now able to register the device to blackberry push service.

I think, that it is possible, to change the bar-file again to apk, but I don’t tested it, because these tools are always online and I don’t want to upload my app.

To install the BAR-File to my blackberry, I uses the DDPB-Tool from here:

Now, you could test if the blackberry could register to the blackberry-push service.

To test if the device will be pushed, you could use a simple poster add-on from google chrome or the HttpRequester from firefox.

Set the following configuration with your blackberry credentials and POST this to the blackberry-server. The authorization is a string, which is configured as followed:

Private BLACKBERRY_PUSH_APPLICATION_ID As String ="XXXX-546353vcgsfsre46424M988518o8645vdgdfd64"
Dim b64 As Base64
Dim Login As String
Login=”Basic “ & b64.EncodeStoS(Login, "UTF8")



multipart/related; boundary=PMasdfglkjhqwert;type=application/xml

Content-Type: application/xml; charset=UTF-8
<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.1//EN" "http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd">
<push-message push-id="999999999"  source-reference="XXXX-546353vcgsfsre46424M988518o8645vdgdfd64"  deliver-before-timestamp="2020-12-31T23:59:59Z">    <address address-value="3E4D4545"/>
<quality-of-service delivery-method="confirmed"/>


You now have to get a push-message on your device with the token under address-value.

Caution: you have to copy the lines above to the request-field with all spaces and CRLF, otherwise the message is not accepted.


If you are using something like Erel’s B4X Push Server, you could change the handler-Class “Send” into:

Sub Handle(req As ServletRequest, resp As ServletResponse)
    If req.GetParameter("password") <> Main.config.Get("PushServerPassword") Then
        resp.SendError(500, "Invalid password")
    End If
    Dim m As Message
    If IsNumber(req.GetParameter("badge")) Then
        m.Badge = req.GetParameter("badge")
    End If
    m.Text = req.GetParameter("text")
    m.Sound = True
    m.HighPriority = True
    m.ExpirationDate = DateTime.Now + DateTime.TicksPerDay
    Dim rows As List = DBUtils.ExecuteMemoryTable(Main.db, _
        "SELECT token, type FROM tokens WHERE updated_time > ?", _
        Array As String (DateTime.Now - DAYS_LIMIT * DateTime.TicksPerDay), 0)
    Dim iosTokens, AndroidTokens, BlackberryTokens As List
    For Each row() As String In rows
        If row(1) = Main.TYPE_IOS Then
            If iosTokens.Size > 900 Then
                CallSubDelayed3(iOSPush, "SendMessageTo", iosTokens, m)
                Dim iosTokens As List
            End If
        End If
        If row(1) = Main.TYPE_ANDROID Then
            If AndroidTokens.Size > 900 Then
                CallSubDelayed3(AndroidPush, "SendMessageTo", AndroidTokens, m)
                Dim AndroidTokens As List
            End If
        End If
        If row(1) = Main.TYPE_Blackberry Then
            If BlackberryTokens.Size > 900 Then
                CallSubDelayed3(BlackberryPush, "SendMessageTo", BlackberryTokens, m)
                Dim BlackberryTokens As List
            End If
        End If
    If iosTokens.Size > 0 Then CallSubDelayed3(iOSPush, "SendMessageTo", iosTokens, m)
    If AndroidTokens.Size > 0 Then CallSubDelayed3(AndroidPush, "SendMessageTo", AndroidTokens, m)
    If BlackberryTokens.Size > 0 Then CallSubDelayed3(BlackberryPush, "SendMessageTo", BlackberryTokens, m)

    resp.Write("Message sent to " & rows.Size & " device(s).")
End Sub

And then add a code modul with the name “BlackberryPush” in such a way:

Sub Process_Globals

End Sub

Public Sub SendMessageTo(Devices As List, msg As Map)
    Dim job As HttpJobBlackberry
    job.Initialize("BlackberryPush", Me)
    job.PostMultipartXML(Devices, msg)
End Sub

Private Sub JobDone(job As HttpJobBlackberry)
    If job.Success=False Then
        Log("Fehler Blackberry Push!")
        Log("Blackberry Push erfolgreich!")
    End If
End Sub

To send the message to the blackberry-server, you could do that in xml-format. To send xml, you have to use a multipart-post, based on jhttp. Tests with okhttp has shown, that the okhttp library rejects the content-type, because it considered it to be invalid. Here a sample-sub:

public Sub PostMultipartXML(Link As String)
    Dim Absender As String = "Blackberry"
    Dim Filename As String = "test.txt"
    Dim Daten As String = "test"
    Dim Zeitstempel As Long = 1452172482568
    Dim Groesse As Int = 1234

    Dim b() As Byte
    Dim eol As String = Chr(13) & Chr(10)

        Dim s As String = _
Content-Type: application/xml; charset=UTF-8
<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.1//EN" "http://www.openmobilealliance.org/tech/DTD/pap_2.1.dtd">
  <push-message push-id="999999999"  source-reference="XXXX-546353vcgsfsre46424M988518o8645vdgdfd64"  deliver-before-timestamp="2020-12-31T23:59:59Z">    <address address-value="3E4D4545"/>
    <quality-of-service delivery-method="confirmed"/>

{"Absender":"${Absender}", "Filename":"${Filename}", "Daten":"${Daten}", "Zeitstempel":"${Zeitstempel}", "Groesse":"${Groesse}"}

    b = s.Replace(CRLF, eol).GetBytes("UTF8")
    PostBytes(Link, b)
    req.SetHeader("Authorization", "Basic GHHFDFDFDBBdh6645grjRNOTg4NTE4bzhpMDQyMDVsN656565QWERRFFRZOVnJONg==")
End Sub

Note, that you can send up to 8KB over the blackberry-push service!

To send a push-message to multiple devices, you can configure the address-string as followed:
Dim Device As List
Dim Devicesstring As String
For i=0 To Device.Size-1
     Devicesstring=Devicesstring & "<address address-value='" & Device.Get(i) & "'/>"

and change the line in the string s to

<push-message push-id="999999999"  source-reference="XXXX-546353vcgsfsre46424M988518o8645vdgdfd64"  deliver-before-timestamp="2020-12-31T23:59:59Z">    ${Devicesstring}

It is always possible to send a push-message to all devices, which are registered under your account with

<address address-value="push_all"/>

In this way, it is no need to program an elaborate adress-database, because the blackberry service will manage that for you.

Not to renounce the okhttp-lib, I made a small project, which uses only for the blackberry-push the multipart-post based on jhttp. You can use it parallel to okttp. Set in your own blackberry-credentials and it should work.

Hope, that someone could use it…


  • BlackberryPushServercode.zip
    4.5 KB · Views: 264
Last edited:


Well-Known Member
Licensed User
Longtime User
I have to give some additional informations to this tutorial because I had some problems with the latest version of my app:

With the newer versions of my app, it was not possible to register my devices to the blackberry-push-service. I don't know why, but I found out, that the two new lines in the GCM-register-code of the 'RegisterDevice'-sub seems to be the problem. I isolate them in the following way:

        Dim jo As JavaObject = i
        jo.RunMethod("setPackage", Array("com.google.android.gms"))
#end if

After that, registration was possible again.

I also made now a production-push-ID account under


because it is valid for 10 years and it works without problems. When register the production-push-account, you have to set an App-ID. I set the App-ID which I got from blackberry after register the push-developer-account in my credentials. So i think, that you first have to get a developer-account before apply a production-push-account.

Under point 5 of the client-side above, i told you to use the blackberry DDPB-Tool to install the bar-file to your blackberry-device. It is more simple to enable 'Deploy' in the blackberry-apk-packager. After enabling the developer-mode in the settings/security, the apk packager can install the bar-file straight on your phone.