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

Android™ Development

Reply
Visitor
Posts: 1
Registered: ‎04-08-2014
My Device: Bold
My Carrier: Vodacom

Register Android application with BIS - is a TCP hack the only way ?!?

Dear blackberry team,

 

I have ported an Android application to Blackberry which runs wonderfully.

I tried to enable the Android application for push services against the BIS infrastructure, but I failed miserably due to lack of thorough and complete documentation.

 

[NOTE: I have conceived a hack that works as an interim solution. The iterim solution is detailed at the end of this post. ]

 

I started out by establishing a working BIS eco-system. 

I could send a push request to BIS from SoapUI and receive that push message successfully using a NATIVE BlackBerry application written in C++. 

 

After creating a working Android application, I attempted to port it to BlackBerry as a BAR file. 

My steps are outlined below:

 

  • Converted the APK to a BAR with the following manifest details ( certain details were ommitted using the <<CLASSIFIED>> substitute)
Archive-Manifest-Version: 1.1
Archive-Created-By: Apk2Bar version 1.6.1

Package-Author: <<CLASSIFIED>>
Package-Author-Id: <<CLASSIFIED>>
Package-Name: com.example.androidforblackberry
Package-Id: <<CLASSIFIED>>
Package-Version: 1.0.1.0
Package-Version-Id: testEK7f_Ti_kSyZ7yczIkT-8bY
Package-Type: application
Package-Architecture: armle-v7

Application-Name: AndroidForBlackberry
Application-Id: <<CLASSIFIED>>
Application-Version: 1.0.1.0
Application-Version-Id: testEK7f_Ti_kSyZ7yczIkT-8bY
Application-Requires-System: Tablet OS/2.0.0.7109
Application-Development-Mode: true

Entry-Point-Name: FullscreenActivity
Entry-Point-Icon: android/res/drawable-mdpi/ic_launcher.png
Entry-Point-Type: Qnx/Android
Entry-Point: android://com.example.androidforblackberry?activity-name=com.example.androidforblackberry.FullscreenActivity
Entry-Point-User-Actions: access_internet,access_shared,play_audio,post_notification
Entry-Point-System-Actions: _sys_use_consumer_push

Archive-Asset-Name: android/res/drawable-mdpi/ic_launcher.png
Archive-Asset-SHA-512-Digest: <<CLASSIFIED>>

Archive-Asset-Name: android/AndroidForBlackberry.apk
Archive-Asset-SHA-512-Digest: <<CLASSIFIED>>
  •  Installed the newly packaged BAR file to a blackberry Q10 device running BB OS version - 10.2.1.2102 using the BlackberryGraphicalAid application. Confirmed that the application runs successfully.

That was the easy part, now to enable BIS push messaging ... 

 

  • I constructed a SoapUI push request message, as below. The source-reference corresponds to my application ID. The address-value corresponds to my blackberry device ID.
--asdfglkjhqwert
Content-Type: application/xml; charset=UTF-8
<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 1.0//EN" "http://www.openmobilealliance.org/tech/DTD/pap_1.0.dtd">
<pap>
<push-message push-id="a00e-1eff85ff6525" 
        source-reference=" <<CLASSIFIED>> "
        deliver-before-timestamp="2020-12-31T23:59:59Z" >
<address address-value=" <<CLASSIFIED>> "/>

<quality-of-service delivery-method="unconfirmed"/>
</push-message>
</pap>
--asdfglkjhqwert
Content-Type: text/plain

0|Hallo There|
--asdfglkjhqwert--

 

  • I receive this push request via BIS on a NATIVE Blackberry application using the supplied Blackberry SDK push utilities. Details regarding the registration of the Blackberry application to BIS is abstracted away within the SDK.

 

  • Since I am working with an Android application, the Blackberry SDK is not at my disposal. To circumvent this constraint I resolved to using a simple HTTP call to register my android application to BIS instead. 

 

  • First Failure: I attempted to register my Android application using an HTTP invocation. Unfortunately, certain information is not attainable from the Android runtime on the Blackberry device (important information such as the device model and os version). This information is required for the HTTP post to complete successfully.

 

  • As an interim I used the URL depicted below. NOTE: the value for serviceid corresponds to my application id (removed for sensitivity). I substituted the other variables with data I thought would make sense ?!? 
http://pushapi.na.blackberry.com/mss/PD_subReg?serviceid=<<CLASSIFIED>>&osversion=10.2.1.2141&model=... BlackBerry Device;deviceside=false;ConnectionType=mds/-/public 
  • Anyway, posting a registration request to that URL returns the following response:
<data contentType="text/plain" contentLength="8"><![CDATA[rc=10001]]></data>
  •  According to Blackberry documentation, the code as listed here, means that the submission was successfull. However, according to seen practice, the result of this first response should be used within a subsequent POST to the BIS server. Since the first response is XML, a subsequent invocation makes no sense ... help ?!?

 

  • Second Failure: Does any sane human being know how the steps to register a Android or Blackberry application using REST / HTTP ? Are my invocations correct ? Do we need to send a push registration request TWICE ?!? ... please help  here ... this does not make sense ...   

 

  • Well ... after failing to register the Android application on the blackberry platform, I resorted to sending a BIS push request in JSON format to the device to see if the Android application responds or makes noise in any way. 

 

  • In order for my Android application to receive any notification I need to add some extra configuration, so I did.

 

  • I unzipped the bar file, and included an android.cfg file with the following contents. NOTE: appid ommitted for security reasons. 
<?xml version="1.0" encoding="utf-8"?> 
<android> 
   <push>
      <appid> <<CLASSIFIED>> </appid> 
      <ppgurl>http://pushapi.na.blackberry.com</ppgurl> 
      <tokenprefix>bb-</tokenprefix>
   </push>
</android>

 

  •  I confirmed that BAR permissions were set correctly within my manifest file. The relevant parts from the manifested outlined in the top section is depicted here again. 

 

...
Entry-Point-User-Actions: access_internet,access_shared,play_audio,post_notification Entry-Point-System-Actions: _sys_use_consumer_push ...
  • I then Zipped the bar archive back. The internal file structure resembles the BB documentation exactly blackberry_documentation. In my case, the final result was:

 

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

 

  • I then deployed the newly packgaged BAR file to blackberry successfully.

 

  • I resorted to sending a BIS push request in JSON format to the device to see if the Android application responds or makes noise in any way. 

 

 

--asdfglkjhqwert
Content-Type: application/xml; charset=UTF-8
<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 1.0//EN" "http://www.openmobilealliance.org/tech/DTD/pap_1.0.dtd">
<pap>
<push-message push-id="<<CLASSIFIED>>" 
        source-reference="<<CLASSIFIED>>"
        deliver-before-timestamp="2020-12-31T23:59:59Z" >
<address address-value="<<CLASSIFIED>>"/>

<quality-of-service delivery-method="unconfirmed"/>
</push-message>
</pap>
--asdfglkjhqwert
Content-Type: text/plain

{"msg" : "0|Hallo Awesome Hey|"}
--asdfglkjhqwert--

 

  •  By sending this JSON formatted message to my NATIVE blackberry application it is received successfully. However, the Android application does not register this content. I presume that it could not, since no push channel was created as the result from failure 1 and failure 2.

 

THE GREAT HACK

 

  • Well, since I have a native application that works well with BIS and push notifications I used that for my Blackberry to Android bridge.
  • I created an Android background service that runs continuously and listens on a defined TCP port.
  • Whenever the native BB app receives a push notification ( or is launched from the Blackberry Hub ), it simply forwards on the message over TCP to my background Android service.
  • In turn, the android service invokes the main Android application's activity to start it up from the dead.

 

  • I would prefer not to use this hack. If someone more acquinted with Blackberry could please help me, I would be most grateful. Thanks !! - Mike