Muestra de código: determinar el estado de un transporte de red mediante la API de red

import net.rim.device.api.io.transport.TransportInfo;
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 ProbeSpecificTransportScreen());
    }
}
class ProbeSpecificTransportScreen extends MainScreen implements FieldChangeListener {
    private TextField _tfTransportStatus;
    private ObjectChoiceField _ocfTransports;
    public ProbeSpecificTransportScreen()
    {
        String[] strTransportNames = 
        {"none", "TCP Cellular", "WAP 1.0/1.1", 
         "WAP 2.0", "MDS", "BIS", "TCP WiFi"
        };
        VerticalFieldManager vfm = new VerticalFieldManager();
        _tfTransportStatus = new TextField(Field.FIELD_HCENTER);
        _tfTransportStatus.setText
            ("Select a transport from the list above, then click 'Probe Transport'");
        _ocfTransports = new ObjectChoiceField
            ("Select Transport to Probe: ", strTransportNames, 
                 0, Field.FIELD_HCENTER);
        _ocfTransports.setEditable(true);
        ButtonField btnProbe = new ButtonField("Probe Transport", Field.FIELD_HCENTER);
        btnProbe.setChangeListener(this);
        vfm.add(_ocfTransports);
        vfm.add(btnProbe);
        vfm.add(_tfTransportStatus);
        add(vfm);
    }
    public void fieldChanged(Field field, int context)
    {
        int intTransportType = _ocfTransports.getSelectedIndex();
        if(intTransportType > 0)
        {
            if(TransportInfo.isTransportTypeAvailable(intTransportType))
            {
                if(TransportInfo.hasSufficientCoverage(intTransportType))
                {
                    _tfTransportStatus.setText
                         ((String)_ocfTransports.getChoice(intTransportType) 
                             + " is available.");
                } else
                {
                    _tfTransportStatus.setText
                         ((String)_ocfTransports.getChoice(intTransportType) 
                             + " is available but has insufficient coverage.");
                }
            } else
            {
                _tfTransportStatus.setText("Sorry, " + 
                     (String)_ocfTransports.getChoice(intTransportType) 
                         + " is not available.");
            }
        } else
        {
            _tfTransportStatus.setText
                ("Please select a transport first, then click 'Probe Transport'");
        }
    }
}
Tema siguiente: API de red

¿Le ha resultado útil esta información? Envíenos sus comentarios.