Android devices can be docked into several different kinds of docks. These include car or home docks and digital versus analog docks. The dock-state is typically closely linked to the charging state as many docks provide power to docked devices.
How the dock-state of the phone affects your update rate depends on your app. You may choose to increase the update frequency of a sports center app when it's in the desktop dock, or disable your updates completely if the device is car docked. Conversely,
you may choose to maximize your updates while car docked if your background service is updating traffic conditions.
The dock state is also broadcast as a sticky Intent
, allowing you to query if the device is docked or not, and if so, in which kind of dock.
Determine the Current Docking State
The dock-state details are included as an extra in a sticky broadcast of the
ACTION_DOCK_EVENT
action. Because it's sticky, you don't need to register a
BroadcastReceiver
. You can simply call registerReceiver()
passing in
null
as the broadcast receiver as shown in the next snippet.
IntentFilter ifilter = new IntentFilter(Intent.ACTION_DOCK_EVENT);
Intent dockStatus = context.registerReceiver(null, ifilter);
You 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;
Determine the Current Dock Type
If a device is docked, it can be docked in any one of four different type of dock:
- Car
- Desk
- Low-End (Analog) Desk
- High-End (Digital) Desk
Note that the latter two options were only introduced to Android in API level 11, so it's good practice to check for all three where you are only interested in the type of dock rather than it being digital or analog specifically:
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 for Changes in the Dock State or Type
Whenever the the device is docked or undocked, the ACTION_DOCK_EVENT
action is broadcast. To monitor changes in the device's dock-state, simply register a broadcast receiver in your application manifest as shown in the snippet
below:
<action android:name="android.intent.action.ACTION_DOCK_EVENT"/>
You can extract the dock type and state within the receiver implementation using the same techniques described in the previous step.
分享到:
相关推荐
This paper gives an introduction to the epipolar geometry, and provides a complete review of the current techniques for estimating the fundamental matrix and its uncertainty. A well-founded measure is...
Determining the required stack sizes for a software project is a crucial part of the development process. The developer aims to create a stable application, while not wasting resources. This ...
MBA投资课程的经典课本 外文版的,直接购买要好几百RMB
Human Language Technology (HLT) and Natural Language Processing (NLP) systems have typically focused on the "factual" aspect of content analysis. Other aspects, including pragmatics, opinion, and ...
For the improvement of reliability, safety and efficiency advanced methods of supervision, fault-detection and fault diagnosis become increasingly important formany technical processes. This holds ...
Analyzing and determining the correct OSI layer Explaining the basics of network theory and concepts Summarizing safety practices Installing and configuring equipment in the appropriate location ...
Elasticity is concerned with determining the strength and load carrying ability of engineering structures including buildings, bridges, cars, planes, and thousands of machine parts that most of us ...
Solving the process of hysteresis without determining the optimal thresholds
Also covered are robust parameter estimation, validation methods, multi-temporal and multi-modality image registration, methods for determining the orientation of an image, methods for identifying ...
Identifying state transition and determining the critical value of the Duffing oscillator are crucial to indicating externalsignal existence and have a great influence on detection accuracy in weak ...
Core Files and Directories of the Android Application 73 Creating an AVD for Your Project 75 Creating a Launch Configuration for Your Project 75 Running Your Android Application in the Emulator 76 ...
too, in New York City, the Brooklyn Bridge and the Empire State Building signify aspects of the vibrant history of our great metropolis. In the buildings, parks, and historic areas that survive in New...
chemists, and biologists all rely on the rapidly evolving field of Chemoinformatics. Chemoinformatics: Theory, Practice & Products is an essential handbook for determining the right ...
dobkin__munro___Determining the Mode.pdfdobkin__munro___Determining the Mode.pdfdobkin__munro___Determining the Mode.pdfdobkin__munro___Determining the Mode.pdfdobkin__munro___Determining the Mode.pdf
Examine the problem of maintaining the quality of big data and discover novel solutions. You will learn the four V’s of big data, including veracity, and study the problem from various angles. The ...
Monitoring Phone State and Phone Activity 334 Monitoring Data Connectivity and Activity 337 Accessing Phone Properties and Status 338 Controlling the Phone 338 Using Bluetooth 339 Introducing ...
Main focus is on the application of the IM and the PMSM in electrical drive systems, where the method of the field-orientated control has been successfully established in the practice, and on the use...
Java™ Performance covers the latest Oracle and third-party tools for monitoring and measuring performance on a wide variety of hardware architectures and operating systems. The authors present dozens...
By determining the probability of the offender residing in various areas, and displaying those results through the use of isopleth or choropleth maps, police efforts to apprehend criminals can be ...
reducible, polynomial degrees of difficulty are defined, and it is shown that the problem of determining tautologyhood has the same polynomial degree as the problem of determining whether the first of...