The status of the base is similar to the charging state, and many bases provide charging function (seat charge).
The base state also uses sticky intent broadcasts. You can query whether the device is plugged into the cradle or the base.
Determine the current cradle status
The broadcast action is Action_dock_event,sticky intent does not need to register a real receiver
Copy Code code as follows:
Intentfilter ifilter = new Intentfilter (intent.action_dock_event);
Intent dockstatus = Context.registerreceiver (null, IFilter);
Can extract the current docking status from the Extra_dock_state EXTRA:
int dockstate = Battery.getintextra (extra_dock_state,-1);
Boolean isdocked = Dockstate!= intent.extra_dock_state_undocked;
To determine the type of insert base
There are four types of insert base:
Copy Code code as follows:
Car
Desktop
Low-end (analog) Desk (guess is show analog clock)
High-end (Digital) Desk (guess is show digital clock)
The following two items were introduced after API11, so the latter three were judged to be the best.
Copy Code code as follows:
Boolean IsCar = Dockstate = = Extra_dock_state_car;
Boolean Isdesk = Dockstate = = Extra_dock_state_desk | |
Dockstate = = Extra_dock_state_le_desk | |
Dockstate = = Extra_dock_state_he_desk;
Monitor charge
The Action_dock_event will broadcast when the cradle is inserted and dialed. So take this ad.
Copy Code code as follows:
<action android:name= "Android.intent.action.ACTION_DOCK_EVENT"/>
You can read the type and state of the insertion cradle in the same way as in the previous step.