title: Detecting if phone is plugged into pc
body: <p>I want to detect if a phone is plugged into a pc or will be unplugged...so in my manifest i have:</p>
  
  <pre><code>&lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name="de.name.usbtest.MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
          &lt;intent-filter&gt;
          &lt;action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /&gt;
      &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;service
          android:name=".MyService"
          &gt;
      &lt;/service&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>My Service Class:</p>
  
  <pre><code>@Override
  public void onCreate() {
      USBBroadcast usbTrigger = null;
      // create new USBTrigger()() and register for ACTION_USB_DEVICE_ATTACHED broadcasts
      usbTrigger = new USBBroadcast();
      registerReceiver(usbTrigger, new IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED));
  }
  </code></pre>
  
  <p>My Broadcastreceiver:</p>
  
  <pre><code>@Override
  public void onReceive(Context ctx, Intent intent) {
      String action = intent.getAction();
      Toast.makeText(ctx, "Received", Toast.LENGTH_SHORT).show();
  }
  </code></pre>
  
  <p>and my Main Activity:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      Intent serviceIntent = new Intent(this, MyService.class);
  
      startService(serviceIntent);
  
      setContentView(R.layout.activity_main);
  
  }
  </code></pre>
  
  <p>But i never see the Toast, when i plug in my phone...Anyone knows why?!</p>