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

Java Development

Reply
Developer
Posts: 129
Registered: ‎09-21-2009
My Device: Not Specified

check connection type

I am currently using the servicebook to check what connection methods are available, however once detected I am a little uncertain as to what I should set it to if "mms" is detected.  Also is this type 3G?  I am checking in the following way,

 

 

    checkConnection() {   
        
        ServiceBook sb = ServiceBook.getSB();
        ServiceRecord[] records = sb.findRecordsByCid("WPTCP");
        String uid = null;
                        
        System.out.println(records.length);
        for(int i=0; i < records.length; i++)
        {
            //Search through all service records to find the
            //valid non-Wi-Fi and non-MMS
            //WAP 2.0 Gateway Service Record.
            if (records[i].isValid() && !records[i].isDisabled())
            {
                System.out.println("serviceBook :" + records[i].getUid().toLowerCase());
                        
                if (records[i].getUid() != null && records[i].getUid().length() != 0)
                {                                    
                    if (records[i].getUid().toLowerCase().indexOf("wifi") > -1){
                        _connMethod = "interface=wifi"
                    }
                    else if (records[i].getUid().toLowerCase().indexOf("mms") > -1){
                        //not sure for here
                        _connMethod = ????
                    }
                    else if ((records[i].getUid().toLowerCase().indexOf("wifi") == -1) &&
                            (records[i].getUid().toLowerCase().indexOf("mms") == -1)){
                                        
                            uid = records[i].getUid();
                            _connMethod = "ConnectionUID=" + uid;
                    }
                    else{
                        //alert an error
                    }
                }
             }
          }
    
     }

 

Is there any other connection type I ahould check for? And what should I set it to for "mms"?  Any help of this would be much appreciated.

 

 

 

 

Highlighted
Developer
Posts: 216
Registered: ‎09-11-2008
My Device: 9000(Bold)

Re: check connection type

 

Hi,

 

The code you are using is verifying the UID you found isn't MMS or WIFI and it is actually lookingo for WAP2 connection.

Regarding your question about different connections you can read the thread:

http://supportforums.blackberry.com/t5/Java-Development/Connecting-your-BlackBerry-http-and-socket-c...

 

Developer
Posts: 129
Registered: ‎09-21-2009
My Device: Not Specified

Re: check connection type

Thanks for the reply.

 

I have read through this thread previously, and have been helped by it.  However I am struggling to find a difinitve way in detecting exactly what is a vailable.  I would like to check for, wifi, 3g, edge, if none available then report an error.

Developer
Posts: 129
Registered: ‎09-21-2009
My Device: Not Specified

Re: check connection type

just found this posted by mantaker,

 

String updateConnectionSuffix()
{
if (DeviceInfo.isSimulator()) {
    connSuffix = ";deviceside=true";
} else
if ( (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) &&
      RadioInfo.areWAFsSupported(RadioInfo.WAF_WLAN)) {
    connSuffix=";interface=wifi";
} else {
    String uid = null;
    ServiceBook sb = ServiceBook.getSB();
    ServiceRecord[] records = sb.findRecordsByCid("WPTCP");
    for (int i = 0; i < records.length; i++) {
        if (records[i].isValid() && !records[i].isDisabled()) {
            if (records[i].getUid() != null &&
                records[i].getUid().length() != 0) {
                if ((records[i].getUid().toLowerCase().indexOf("wptcp") != -1) &&
                    (records[i].getUid().toLowerCase().indexOf("wifi") == -1) &&
                    (records[i].getUid().toLowerCase().indexOf("mms") == -1)   ) {
                    uid = records[i].getUid();
                    break;
                }
            }
        }
    }
    if (uid != null) {
        // WAP2 Connection
         connSuffix = ";ConnectionUID="+uid;
    } else {
         connSuffix = ";deviceside=true";
    }
}
return connSuffix
};

 

I think this does what I ask. Thank you

 

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: check connection type

What OS are you targetting?  Have you looked at CoverageInfo?

Developer
Posts: 129
Registered: ‎09-21-2009
My Device: Not Specified

Re: check connection type

Targetting 4.6 onwards, no I haven't looked at CovergaeInfo, is this an alternative to serviceBook?

 

Just looking for the best way to get the app to first use wifi then 3g.

Developer
Posts: 129
Registered: ‎09-21-2009
My Device: Not Specified

Re: check connection type

also with the code I pasted, what if there is no connection at all?  I do not see how that is captured?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: check connection type

I think CoverageInfo is your best option - this just provides a friendly version of the ServiceRecords anyway..  Re using WiFi first then wireless, I would only do that in a non BES/MDS device - if the device has BES/MDS then let the device try to route it over WiFi if it can, or never use BES/MDS.