is there a solution for a popup to appear on all the pages of the application if the user does not have an internet connection ? Thank you
            Asked
            
        
        
            Active
            
        
            Viewed 131 times
        
    0
            
            
        - 
                    3Does this answer your question? [Android: Internet connectivity change listener](https://stackoverflow.com/questions/25678216/android-internet-connectivity-change-listener) – ATP Jan 07 '21 at 12:36
- 
                    it's in java, I want to do it in Kotlin – admindunet Jan 07 '21 at 12:48
- 
                    https://stackoverflow.com/a/55422512 – ATP Jan 07 '21 at 13:24
2 Answers
0
            
            
        You can simply create an activity with an error message. So whenever there's no internet connection then show them no internet connection activity. You can also give a message in a toast or snack bar.
 
    
    
        Rutul Ganatra
        
- 1
- 1
0
            
            
        You can use this method
fun isNetworkConnected(context: Context) : Boolean {
    val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
    val capabilities =  connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
    capabilities.also {
        if (it != null){
            if (it.hasTransport(NetworkCapabilities.TRANSPORT_WIFI))
                return true
            else if (it.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)){
                return true
            }
        }
    }
    return false
}
you can check internet connection every where you want.
    if(isNetworkConnected()){
     // do something
     }
    else{
     // use toast or a dialog to say internet is not connected
     }
and don't forget to add this permissions to manifst
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
 
    
    
        Sadegh J
        
- 1,603
- 2
- 9
- 22
- 
                    i get : 'getter for activeNetworkInfo: NetworkInfo?' is deprecated. Deprecated in Java 'getter for isAvailable: Boolean' is deprecated. Deprecated in Java 'getter for isConnected: Boolean' is deprecated. Deprecated in Java 'getter for isFailover: Boolean' is deprecated. Deprecated in Java 'getter for isRoaming: Boolean' is deprecated. Deprecated in Java – – admindunet Jan 07 '21 at 17:05
- 
                    
 
    