Setting up a paid subscription option for Mobislim BMI Java App

6 01 2009

Extending the basic Java application using Bango’s web services.


Following on from my first post, my second objective was to develop a way to make it so that my application will only work if the user has a valid Bango subscription with some time remaining on it. This started with quite a lot of research into how I was going to do it.


The first obvious problem was how to get the application to find out if the user has a valid and active subscription.  I played around with a few different techniques and approaches, the one that appeared to be the most successful was to have the application connect to a web server which would then send a web service request to Bango. The web server then returns some data to the phone (Illustrated right).


So the first stage was to develop a script on the web server to get the correct information to the device. The information I needed to get to the device was really only the time remaining on the subscription. I did however actually decide to send a few extra pieces of data to the phone too though for some further ideas I had.


To get the subscription status, we have to go through three major stages:

  1. Get the users Bango user ID
  2. Get the users active subscriptions on a Bango number
  3. Get the time remaining on the subscription


To do this I used PHP as my server-side scripting language, and this is what I came up with.




$username = “myusername”; // Bango web services username

$password = “mypassword”; // Bango web services password

$bango    = “000111222333”; // Bango number with subscriptions

$script   = “;; // URL of this script




       $client = new SoapClient(“;);


       $SubscriptionID = $client->GetSubscriptionID(array(“request” =>

       array( “username”    => $username,

              “password”    => $password,

              “bango”       => $bango,

              “userId”      => $_GET[‘u’])



       $SubscriptionInfo = $client->GetSubscriptionInfo(array(“request” =>

       array( “username”        => $username,

              “password”        => $password,

              “subscriptionId”  => $SubscriptionID->GetSubscriptionIDResult->subscriptionId)



// Redirect to same script, but only with the variable we need.

// We then scrape the variable in the app.

       header(“HTTP/1.1 301 Moved Permanently”);

       header(“Location: ” . $script . “?time=” . $SubscriptionInfo->GetSubscriptionInfoResult->accessMinutesRemaining);







I did actually have quite a few problems with PHP and SOAP. There are quite a few ways of using SOAP; I used the PHP SOAP module (


I then setup a Bango number with the identifier function enabled which redirects to the script. I was now set to work on two more things:

  1. Getting the data into the application
  2. Using the data to make the application expire


String scripturl = “;; // The same url you entered in the php script

String bangoid = “444333222111”; //the bango number with identifier function turned on


       HttpConnection conn = null;


       String url = “; + bangoid + “&register=n”;

        try {

           while (true) {

               conn = (HttpConnection) url );

               conn.setRequestProperty( “User-Agent”, “Mozilla/4.0” );


               rc = conn.getResponseCode();


               if ((rc == HttpConnection.HTTP_TEMP_REDIRECT) ||

               (rc == HttpConnection.HTTP_MOVED_TEMP) ||

               (rc == HttpConnection.HTTP_MOVED_PERM)) {

                   // Get the new location and close the connection

                   url = conn.getHeaderField(“location”);



               } else {


       String timeremaining = replaceAll(conn.getURL(),scripturl + “?time=”,””);









        }catch( IOException e ){

           // handle the error here



This also requires a small method called replaceAll, below.


private String replaceAll(String text, String searchString, String replacementString){

    StringBuffer sBuffer = new StringBuffer();

    int pos = 0;

    while((pos = text.indexOf(searchString)) != -1){

        sBuffer.append(text.substring(0, pos) + replacementString);

        text = text.substring(pos + searchString.length());



        return sBuffer.toString();



I then just compared the variable timeremaining against 0. If the number is greater than 0, the application will start. If not we tell the user that the subscription doesn’t exist or has expired.


if(Integer.parseInt(timeremaining) > 0){

       // Code if not expired


       // Code if expired



What could be easier?





2 responses

11 01 2009

First of all congratulation for such a great site. I learned a lot reading here today. I will make sure i visit this site more often so i can learn more.

4 02 2009

I must congratulate you for your great effort.Nice informative blog.Carry on.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: