@@ -34,22 +34,65 @@ Step 2. Add the dependency.
3434
3535| Releases
3636| ------------- |
37- | 3.1 .0 |
37+ | 3.3 .0 |
3838
3939
4040# Usages
4141
4242## Step 1:
43- Initialize ` NetworkX ` from your ` Application.onCreate() ` method by calling ` NetworkXProvider.init() ` which take ` Application ` reference as the param.
43+ Initialize ` NetworkX ` from your ` Application.onCreate() `
44+ ````
45+ val builder = NetworkXConfig.Builder()
46+ .withApplication(this)
47+ // You can disable speed meter if not required
48+ .withEnableSpeedMeter(true)
49+ .build()
50+ NetworkXProvider.enable(builder)
51+ ````
4452
4553## Step 2:
4654- To check internet connection status, simply call ` NetworkXProvider.isInternetConnected ` which return a ` Boolean ` value.
55+ ````
56+ val status = NetworkXProvider.isInternetConnected
57+ textView.text = "Internet connection status: $status"
58+ ````
4759
4860- To observe the internet connection status, start observing ` NetworkXProvider.isInternetConnectedLiveData `
4961
50- ## Note:
62+ ````
63+ NetworkXProvider.isInternetConnectedLiveData.observe(this) { status ->
64+ status?.let {
65+ textView.text = "Internet connection status: $it"
66+ }
67+ }
68+ ````
69+
70+ - To get connected network speed/last known speed call ` NetworkXProvider.lastKnownSpeed ` which return an ` LastKnownSpeed ` object
71+
72+ ````
73+ NetworkXProvider.lastKnownSpeed?.let {
74+ textView2.text =
75+ "Last Known Speed: Speed - ${it.speed} | Type - ${it.networkTypeNetwork} | Simplified Speed - ${it.simplifiedSpeed}"
76+ }
77+ ````
78+
79+ - To obsever current network speed/last known speed start observing ` NetworkXProvider.lastKnownSpeedLiveData `
80+
81+ ````
82+ NetworkXProvider.lastKnownSpeedLiveData.observe(this) {
83+ it?.let {
84+ textView2.text =
85+ "Last Known Speed: Speed - ${it.speed} | Type - ${it.networkTypeNetwork} | Simplified Speed - ${it.simplifiedSpeed}"
86+ }
87+ }
88+ ````
89+
90+ ## Notes:
91+ - NetworkX (including Speed Meter) only works when the app is in the foreground
5192 - The default value for ` NetworkXProvider.isInternetConnected ` is ` false `
5293 - The default value for ` NetworkXProvider.isInternetConnectedLiveData ` is ` null `
94+ - The default value for ` NetworkXProvider.lastKnownSpeed ` is ` null `
95+ - The default value for ` NetworkXProvider.lastKnownSpeedLiveData ` is ` null `
5396
5497---
5598
0 commit comments