Simple library for getting basic connection information on codename one
Objective-C Java JavaScript C#
Latest commit f141afe Feb 14, 2016 @DigNZ DigNZ Merge pull request #1 from codenameone/master
Added binary and added a link to it in the readme
Permalink
Failed to load latest commit information.
lib Initial Commit Sep 28, 2015
native Initial Commit Sep 28, 2015
nbproject Initial Commit Sep 28, 2015
src/org/littlemonkey/connectivity Initial Commit Sep 28, 2015
Connectivity.cn1lib
LICENSE Create LICENSE Sep 28, 2015
README.md Updated readme to link to the file Feb 14, 2016
Stubber.jar Initial Commit Sep 28, 2015
build.xml Initial Commit Sep 28, 2015
codenameone_library_appended.properties Initial Commit Sep 28, 2015
codenameone_library_required.properties Initial Commit Sep 28, 2015
manifest.mf Initial Commit Sep 28, 2015
manifest.properties Initial Commit Sep 28, 2015

README.md

codenameone-connectivity

Simple library for getting basic connection information on codename one

Installation

Just install as any other cn1lib, copy the file to the libs folder of your project and refresh libs. If the build hints don't merge automatically these are the lines to add to codename_settings.properties

codename1.arg.android.xpermissions=<uses-permission android\:name\="android.permission.ACCESS_NETWORK_STATE"/>
codename1.arg.ios.add_libs=SystemConfiguration.framework

Usage

There are only two methods here is an example of each

Check for any connection

if (Connectivity.isConnected()) {
    //we have some connection
} else {
    // we have no connection
}

Check what type of connection

        ConnectionState status = Connectivity.getConnectionState();
        switch (status) {
            case DISCONNECTED:
                Log.p("Disconnected");
                break;
            case WIFI:
                Log.p("On Wifi");
                break;
            case MOBILE:
                Log.p("On Mobile Data");
                break;
            default:
                //shouldn't be possible

        }

Note

This doesn't mean you can connect to a particular host, but helps check that a connection is available and lets you provide friendly messages to the user before attempting connection requests. Also you can use the connection type to warn about large downloads over mobile data etc.,

On Android and iOS uses native code to check and return the values. On other platforms including the simulator it just makes a connection request to NetworkManager.getAutoDetectURL(). On platforms other than iOS and Android Connectivity.getConnectionState() will only return DISCONNECTED or WIFI. WIFI means connected regardless of connection method.