private fun checkConnectivity(context: Context) {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork: NetworkInfo? = cm.activeNetworkInfo
val isConnected: Boolean = activeNetwork?.isConnectedOrConnecting == true
//Alert Dialog box
val alertDialog: AlertDialog? = this.let {
val builder = AlertDialog.Builder(it)
builder.apply {
setPositiveButton(R.string.OK,
DialogInterface.OnClickListener { dialog, id ->
// User clicked OK button
})
}
builder.setTitle(R.string.no_internet_connexion)
builder.setMessage(R.string.offline_message)
// Create the AlertDialog
builder.create()
}
if (!isConnected) {
alertDialog?.show()
}
}
Line in bold is deprecated according to Android Studio.
private fun checkConnectivity(context: Context) { val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val activeNetwork: NetworkInfo? = cm.activeNetworkInfo val isConnected: Boolean = activeNetwork?.isConnectedOrConnecting == true //Alert Dialog box val alertDialog: AlertDialog? = this.let { val builder = AlertDialog.Builder(it) builder.apply { setPositiveButton(R.string.OK, DialogInterface.OnClickListener { dialog, id -> // User clicked OK button }) } builder.setTitle(R.string.no_internet_connexion) builder.setMessage(R.string.offline_message) // Create the AlertDialog builder.create() } if (!isConnected) { alertDialog?.show() } }Line in bold is deprecated according to Android Studio.