0

I need to know when the device is connected or disconnected to a dock (car or desk). To do that I have a broadcast receiver and this line in the Manifest:

<action android:name="android.intent.action.ACTION_DOCK_EVENT"/>

And this is the receiver:

@Override public void onReceive(Context context, Intent intent)
{  
   if(intent.getAction().equals("android.intent.action.ACTION_DOCK_EVENT")
   {  //This is a Dock event.
      //How can I know here if the event is connected or disconnected?
      //Can I also know if is it is a Car or a Desk dock?
   }
}

How can I know here if the event is connected or disconnected? Can I also know if is it is a Car or a Desk dock?

Ton
  • 9,235
  • 15
  • 59
  • 103

1 Answers1

1

You can find both of those by looking at the intent's extras. An explanation and example code is found here: http://developer.android.com/training/monitoring-device-state/docking-monitoring.html

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Sorry, I already looked at it but I don't understand it. In the line: "int dockState = battery.getIntExtra(EXTRA_DOCK_STATE, -1);" What is "battery"???? – Ton May 29 '14 at 23:22
  • It's the incoming intent. Probably a copy paste bug from the battery documents. – Gabe Sechan May 29 '14 at 23:27