- ACTION_DOCK_EVENT. , BroadcastReceiver. registerReceiver(), , .
mContext = getApplicationContext();
IntentFilter ifilter = new IntentFilter(Intent.ACTION_DOCK_EVENT);
Intent dockStatus = registerReceiver(null, ifilter);
You can extract the current docking status from EXTRA_DOCK_STATE additionally:
int dockState = (dockStatus == null ?
Intent.EXTRA_DOCK_STATE_UNDOCKED :
dockStatus.getIntExtra(Intent.EXTRA_DOCK_STATE, -1));
boolean isDocked = dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED;
boolean isCar = dockState == Intent.EXTRA_DOCK_STATE_CAR;
Whenever a device is docked or undocked, the ACTION_DOCK_EVENT action is broadcast. To track changes in the device dock state, simply register the broadcast receiver in the application manifest, as shown in the following snippet below: action android: name = "android.intent.action.ACTION_DOCK_EVENT"
Hope this helps.
source
share