How to Determine the Current Dock Type in Android?
Prerequisite: How to Check if the Android Device is in Dock State?
An Android Device is said to be DOCKED when it is connected to a power supply or a metered exchange system involving the charging and the exchange of multimedia. Dock State is very closely related to the Charging State of the device. Dock State gives insights regarding the charging or the connection type. Android devices are capable of docking into several kinds of docks. For example, when an Android device is connected to a music system such as a Home Music System over a compatible USB cable, it is said to be DOCKED in a High-End Desk. Similarly, when an Android device is connected to a car charger, it is DOCKED in a Car. So basically, there are four different types of dock:
- Low-End (Analog) Desk
- High-End (Digital) Desk
Note: The Low-End (Analog) Desk and the High-End (Digital) Desk were introduced to Android in API level 11.
- Car Dock: A Car Dock is a docking center, that lets the device charge, and transfers media when connected.
- Desk Dock: A Desk Dock is a docking station, which is an interface device allowing portable computers with little or no effort to attach to other devices. Docking stations enable mobile devices to convert it to a desktop computer at the office or home.
- Low-End Desk: These docks are operated at a lower current. Ex: Low Output Power Banks (<1 Ampere)
- High-End Desk: These docks are operated at a higher current. Ex: Fast Chargers, High Output Power Banks (2.1 Amperes)
So in this article let’s determine the current dock type in Android. Note that we are going to implement this project using the Kotlin language.
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.
Step 2: Working with the activity_main.xml file
There is nothing to do with the activity_main.xml file. So keep the file as it is.
Step 3: Working with the MainActivity.kt file
Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.
Depending upon the state, the application shows Toast messages, “Dock CAR” when the device is docked in a Car, “Dock DESK” if docked on a desk, or “Not Docked” otherwise. The output is not available but this is the standard version of extracting the dock state in Android.