Code sample: Determining network transports with sufficient coverage using the Network API

import net.rim.device.api.io.transport.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

public class NetworkSample extends UiApplication 
{
    public static void main(String[] args) 
    {
        NetworkSample app = new NetworkSample();
        app.enterEventDispatcher();
    }
    public NetworkSample() {
        pushScreen(new ListTransportsWithCoverageScreen());
    }
}


class ListTransportsWithCoverageScreen extends MainScreen
{

    private int[] _transportsWithCoverage;
    private TransportDescriptor[] _transports;
    private RichTextField _rtfDisplay;
    private ButtonField _btnShowTransports;

    public ListTransportsWithCoverageScreen()
    {
        VerticalFieldManager vfm = new VerticalFieldManager();
        setTitle("Network Sample");
        _rtfDisplay = new RichTextField
             ("Click button below to display available transports.");
        _btnShowTransports = new ButtonField
             ("Show Transports", Field.FIELD_HCENTER);
        _btnShowTransports.setChangeListener(new FieldChangeListener()
        {
            public void fieldChanged(Field field, int context)
            {
                getTransports();
            }
        });
        vfm.add(_rtfDisplay);
        vfm.add(_btnShowTransports);
        add(vfm);

    }

    public void getTransports()
    {
        StringBuffer sb = new StringBuffer();
        sb.append("The transports currently available are: \n");
        _transportsWithCoverage = TransportInfo.getCoverageStatus();
        _transports = TransportInfo.getTransportDescriptors
                          (_transportsWithCoverage);
        for(int i = _transports.length - 1; i >=0; --i)
        {
            switch(_transports[i].getTransportType())
            {
            case TransportInfo.TRANSPORT_BIS_B:
                sb.append("BlackBerry Internet Service\n");
                break;
            case TransportInfo.TRANSPORT_MDS:
                sb.append("BlackBerry Mobile Data Service\n");
                break;
            case TransportInfo.TRANSPORT_TCP_CELLULAR:
                sb.append("TCP Cellular\n");
                break;
            case TransportInfo.TRANSPORT_TCP_WIFI:
                sb.append("TCP WiFi\n");
                break;
            case TransportInfo.TRANSPORT_WAP:
                sb.append("WAP 1.0 or 1.1\n");
                break;
            case TransportInfo.TRANSPORT_WAP2:
                sb.append("WAP 2.0\n");
                break;
           }
        }
        _rtfDisplay.setText(sb.toString());
    }
}

Was this information helpful? Send us your comments.