Exploring Android 12: VibratorManager & New Vibration Primitives

M Farhan Majid
2 min readMar 18, 2022

Android 12 offers several new features for enhancing haptic experience. One of them is by introducing a new class for managing vibrations: VibratorManager. Before Android 12, developer uses Vibrator class instead of VibratorManager. You can read more detail about Vibrator class that in this article.

Android 12 also introduces 3 new vibration primitives that developer can use for their app:

  1. Low tick vibration: Very short low frequency effect intended to be used repetitively for dynamic feedback.
  2. Spin vibration: Simulates spinning momentum.
  3. Thud vibration: Simulates downward movement with gravity.

In this article, we will create a simple application that utilizes VibratorManager and the three new vibration primitives.

Where’s the Source Code?

Step by Step Explanation

Follow the steps provided below to create this application.

1. Open Android Studio. Create new project with “Empty Activity” option.

2. Add android.permission.VIBRATE to your AndroidManifest.xml like this:

3. Next, we will update our activity_main.xml file first. The image below shows you how the layout should look like. It contains of three buttons that will perform the new primitive vibration whenever it’s clicked.

This is how activity_main.xml should look like.

To create this layout, open activity_main.xml file and copy-paste the code below:

4. Lastly, we need to update our MainActivity.kt file. You can go ahead and copy-paste the code snippet below, but here’s how it works. First it obtains VibratorManager object through system service. And then it setups a click listener for each button. When a button is clicked, it checks whether the device support the primitive vibration or not. If it does, it will perform that vibration.

5. That’s it! Now you can run this app on your Android 12 device and feel the new vibrations for yourself.

As always, thanks for reading!

Want to learn more about Android 12?

Check out all of our articles from “Exploring Android 12” series here:

Exploring Android 12

9 stories

--

--