Listening for Docking Changes in Android

Android devices can be docked in either a car dock or desk dock. These, in term, can be either analog or digital docks. By registering a Receiver to listen for the Intent.ACTION_DOCK_EVENT (android. intent.action.ACTION_DOCK_EVENT), you can determine the docking status and type of dock

Determining docking state information

IntentFilter dockIntentFilter = 
 new IntentFilter(Intent.ACTION_DOCK_EVENT);
Intent dock = registerReceiver(null, dockIntentFilter);
int dockState = dock.getIntExtra(Intent.EXTRA_DOCK_STATE,
boolean isDocked = dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED;

Leave a Comment