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?



Building the Mobislim BMI Java App

2 01 2009

I started out with the objective of creating an application for mobile. Even with my limited knowledge of Java and having never programmed anything for mobile before, it was surprisingly simple.


The first thing I did was go to the Java website where I found the Java Mobile Edition Software Development Kit ( I downloaded it, and then tried to install it. Unfortunately, it wouldn’t let me install it as I was missing the Java Development Kit. I went back to the Java site and found it on this page It is worth noting that the top download is the Java Runtime Environment. I almost made the mistake of downloading it, the one I needed for Java ME was the Java SE Development Kit.


Once the Java SDK had finished downloading, I installed it, and then installed Java ME. Both installed without errors, so I went ahead and started up Java ME.


Once Java ME had started, I created a project by clicking File -> New Project -> Java ME SDK -> MIDP Application.


After clicking next, I entered “HelloWorld” as my Project Name. As it was my first time using Java ME, I left the two checkboxes checked as they were by default. The HelloMIDlet created a simple hello world MIDlet for me, which I found really useful in getting going.


After clicking next again, I selected the DefaultCldcJtwiPhone1 from the drop down list. This was as it had the lowest phone requirements, so I assumed that it would work on the greatest number of phones.


I clicked finish, and I was presented with my project on the left hand side, and my HelloMIDletcode on the right. I decided to see what the default code did by clicking the “Run Main Project via OTA” button. This is the blue button at the top with a green play button on it. The application started up in the emulator and said Hello World. Great!


Next, I played with the default code seeing what I could do, but I found the default code very limiting. After about 10 minutes, I had created my own version of the hello world application, which was a really good starting point. This is the code I came up with:


    public void startApp() {


        // Create a form with the title My First App

        Form mainForm = new Form(“My First App”);


        // Add the text “Hello World” to the page

        mainForm.append(“Hello World”);


        // Add an exit button to the page




        // Display the page





Anything that I now put in the area where it says Hello World would now appear within my application. Easy!

Adding a useful App to Mobislim

1 01 2009

There is a bit of a craze these days around the iPhone of downloading little “apps” from iTunes.  

With normal phones there is no need to go through Apple, you can just post apps on your website and phone users can download them – at least thats the theory.

I decided to post up a simple Body Mass Index app at Mobislim and see
(a) how it worked
(b) how easy it is to “monetize the app” by selling it
(c) how I can set up a monthly subscription version of the BMI app
(d) what sort of people download apps and how successful they are

My posts will record my progress!