Skip to content

Commit 82fddbf

Browse files
committed
Merge origin/master
2 parents a58f8ab + 144ac08 commit 82fddbf

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Littlemonkey Ltd
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# codenameone-connectivity
2+
Simple library for getting basic connection information on codename one
3+
4+
## Installation
5+
Just install as any other cn1lib, copy the file to the libs folder of your project and refresh libs.
6+
If the build hints don't merge automatically these are the lines to add to codename_settings.properties
7+
8+
```
9+
codename1.arg.android.xpermissions=<uses-permission android\:name\="android.permission.ACCESS_NETWORK_STATE"/>
10+
codename1.arg.ios.add_libs=SystemConfiguration.framework
11+
```
12+
13+
## Usage
14+
There are only two methods here is an example of each
15+
16+
Check for any connection
17+
```
18+
if (Connectivity.isConnected()) {
19+
//we have some connection
20+
} else {
21+
// we have no connection
22+
}
23+
```
24+
25+
Check what type of connection
26+
```
27+
ConnectionState status = Connectivity.getConnectionState();
28+
switch (status) {
29+
case DISCONNECTED:
30+
Log.p("Disconnected");
31+
break;
32+
case WIFI:
33+
Log.p("On Wifi");
34+
break;
35+
case MOBILE:
36+
Log.p("On Mobile Data");
37+
break;
38+
default:
39+
//shouldn't be possible
40+
41+
}
42+
```
43+
44+
## Note
45+
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.,
46+
47+
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.

0 commit comments

Comments
 (0)