How to properly build HTTP connection suffix

1.6k Views Asked by At

I have written code to get a location name using Google Maps reverse geocoding, for example: http://maps.google.com/maps/geo?json&ll=9.6,73.7

How can I add an appropriate HTTP connection suffix to the above URL?

I have tried the following function:

private static String getConnectionStringForGoogleMap(){
    String connectionString="";
    if(WLANInfo.getWLANState()==WLANInfo.WLAN_STATE_CONNECTED){
        connectionString="&interface=wifi";
    }   
     else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS){
         connectionString = "&deviceside=false";
    }
        else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT)==CoverageInfo.COVERAGE_DIRECT){
            String carrierUid=getCarrierBIBSUid();
            if(carrierUid == null) {
                connectionString = "&deviceside=true";
            }
            else{
                 connectionString = "&deviceside=false&connectionUID="+carrierUid + "&ConnectionType=mds-public";
                }

            }
     else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE)
        {

        }
    return connectionString;
    }

When I run the application in the simulator, I create the URL like this: http://maps.google.com/maps/geo?json&ll=9.6,73.7+getConnectionStringForGoogleMap();

But I get a tunnel exception and am not sure what to do next.

This URL also leads to an exception: http://maps.google.com/maps/geo?json&ll=9.6,73.7&deviceside=false&ConnectionType=mds-public

As does: http://maps.google.com/maps/geo?json&ll=9.6,73.7;deviceside=false;ConnectionType=mds-public

I am confused about what to do to get this to work.

5

There are 5 best solutions below

1
On

You definitely want semi-colons (;) and not ampersands (&). Are you tring to run this on the simulator? If so, do you have the MDS simulator running? That is required in order to use devicside=false on the simulator.

0
On

There is a very good posting about this on the BlackBerry Java development forum, complete with sample HTTP connection code.

0
On

Try using Versatile Monkey's networking helper class to find the best path for your HTTP connection and avoid those tunnel exceptions. And form the URL with the correct syntax.

0
On
0
On

If you are targeting OS5 and above you can use ConnectionFactory. This takes a lot of the hard work out of establishing the correct connection type.