title: How to detect my android device is connected with usb or car dock through Broadcast Receiver?
body: <p>I am trying with Broadcast Receiver to get the my device is connected to usb or car dock but not getting the proper result. 
  Please help?
  Thanks in advance.
  Receiver code is:</p>
  
  <pre><code>public class CarDockReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
          Toast.makeText(context, "Car Dock Receiver registerd", Toast.LENGTH_SHORT).show();
          switch (intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1)) {
          case BatteryManager.BATTERY_PLUGGED_AC:
              Toast.makeText(context, "Battery plugged AC", Toast.LENGTH_SHORT).show();
              break;
          case BatteryManager.BATTERY_PLUGGED_USB:
              Toast.makeText(context, "Battery plugged USB", Toast.LENGTH_SHORT).show();
              break;
          default:
              break;
          }
      }
  }
  </code></pre>
  
  <p>receiver in Manifest file is:</p>
  
  <pre><code>&lt;receiver
       android:name=".CarDockReceiver"
       android:enabled="true" &gt;
       &lt;intent-filter&gt;
          &lt;action android:name="android.intent.action.ACTION_POWER_CONNECTED"/&gt;
          &lt;action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/&gt;
       &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>