title: Check when mobile data is connected using BroadcastReceiver | Android
body: <p>I would like to know how can I check when mobile data is connected using BroadcastReceiver.</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>    private BroadcastReceiver MobileDataStateChangedReceiver = new BroadcastReceiver() {
      @Override
      public void onReceive(Context context, Intent intent) {
          int state = intent.getIntExtra(TelephonyManager.EXTRA_STATE,
                  TelephonyManager.DATA_DISCONNECTED);
  
          if (state == TelephonyManager.DATA_CONNECTED) {
              mobileStatus.setText("Connected");
          } else if (state == TelephonyManager.DATA_DISCONNECTED) {
              mobileStatus.setText("Disconnected");
          }
      }
  };
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.status_page);
  
      mobileStatus = (TextView) this.findViewById(R.id.textView4);
  
      registerReceiver(MobileDataStateChangedReceiver, new IntentFilter(
              TelephonyManager.ACTION_PHONE_STATE_CHANGED));
  }
  </code></pre>
  
  <p>What am I doing wrong in here?</p>
  
  <p>I used the same concept on Wi-Fi checking and it worked great?
  I am using the permissions of:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  </code></pre>