What I really want is, when the user has no connection, I want to show some dialog that he or she has no connection.
I tried to put this on my MainActivity but still didn't work.
public boolean isOnline() {
 ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
 return cm.getActiveNetworkInfo().isConnectedOrConnecting();
}
I also used this one but it didn't also work:
public class ConnectionChangeReceiver extends BroadcastReceiver
    {
      @Override
      public void onReceive( Context context, Intent intent )
      {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY_SERVICE );
        NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
        NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(     ConnectivityManager.TYPE_MOBILE );
        if ( activeNetInfo != null )
        {
          Toast.makeText( context, "Active Network Type : " + activeNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show();
        }
        if( mobNetInfo != null )
        {
          Toast.makeText( context, "Mobile Network Type : " + mobNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show();
        }
      }
    }
I added this on my manifest:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Can someone tell me what I'm doing wrong, I would really appreciate it a lot. Thanks in advance!
 
     
     
     
     
     
     
     
     
    