-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
671b948
commit e652187
Showing
7 changed files
with
89 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
app/src/main/java/com/example/network_monitoring/MainActivity.kt
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
app/src/main/java/com/example/network_monitoring/NetworkMonitorWithUi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.example.network_monitoring | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.util.Log | ||
import com.example.networkmonitor.NetworkMonitor | ||
import com.example.networkmonitor.NetworkStatusView | ||
|
||
class NetworkMonitorWithUi : AppCompatActivity() { | ||
private lateinit var networkStatusView: NetworkStatusView | ||
private lateinit var networkMonitor:NetworkMonitor | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
networkStatusView = findViewById(R.id.network_status_view) | ||
|
||
networkStatusView.startMonitoring(this) | ||
|
||
|
||
// Network monitoring api. | ||
networkMonitor = NetworkMonitor(this) | ||
networkMonitor.networkStatus.observe(this) { | ||
if (it) { | ||
// Connection on | ||
Log.e("#", it.toString() + " " + networkMonitor.isNetworkAvailable()) | ||
} else { | ||
// Connection off | ||
Log.e("#", it.toString() + " " + networkMonitor.isNetworkAvailable()) | ||
} | ||
} | ||
|
||
// If you dont want to observe. | ||
val isNetworkAvailable=networkMonitor.isNetworkAvailable() | ||
|
||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
// Stop monitoring. | ||
networkStatusView.stopMonitoring() | ||
|
||
// Stop obeserving. | ||
networkMonitor.unregisterCallback() | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/example/network_monitoring/NetworkMonitorWithoutUi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.example.network_monitoring | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.example.networkmonitor.NetworkMonitor | ||
|
||
class NetworkMonitorWithoutUi : AppCompatActivity() { | ||
private lateinit var networkMonitor: NetworkMonitor | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
// Network monitoring api. | ||
networkMonitor = NetworkMonitor(this) | ||
|
||
networkMonitor.networkStatus.observe(this) { | ||
if (it) { | ||
// Connection on | ||
Log.e("#", it.toString() + " " + networkMonitor.isNetworkAvailable()) | ||
} else { | ||
// Connection off | ||
Log.e("#", it.toString() + " " + networkMonitor.isNetworkAvailable()) | ||
} | ||
} | ||
|
||
// If you dont want to observe. | ||
val isNetworkAvailable=networkMonitor.isNetworkAvailable() | ||
|
||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
// Stop obeserving. | ||
networkMonitor.unregisterCallback() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,6 @@ class NetworkMonitor(context: Context) { | |
} | ||
|
||
init { | ||
|
||
if (!isNetworkAvailable) | ||
isFirstTime = false | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters