Introduction to Android judgment and monitoring base status and type _android

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.