Context
When the vibration setting is disabled in HarmonyOS system settings, the vibration rules set via the @ohos.vibrator library become invalid. This behavior is inconsistent with Android systems, where vibration still responds even if the system vibration setting is disabled.
Description
In HarmonyOS, vibration functionality can be controlled through the @ohos.vibrator module. The startVibration() API is used to trigger motor vibration based on specified vibration effects and attributes.
- usage: Represents the vibration usage scenario.
-
Control switches for vibration functionality:
-
Tri-state switch
- Location: Settings → Sound & Vibration → Ring/Vibrate/Silent (or via the control panel Ring/Vibrate/Silent).
-
Function: A multi-state switch that allows the user to select sound and vibration modes. Specifically:
- Ring mode (device emits sound)
- Vibration mode (device vibrates when receiving notifications)
- Silent mode (device neither emits sound nor vibrates).
-
Haptic feedback switch
- Location: Settings → Sound & Vibration → System Haptic Feedback.
- Function: Controls haptic feedback, determining whether the user receives vibration-based physical feedback during UI operations.
-
Tri-state switch
-
Hardware limitations:
- Real device testing is required since emulators do not support physical vibration functionality.
Solution / Approach
The vibration feature follows different control rules under various usage scenarios. Developers must strictly follow these control rules; otherwise, the behavior may not match expectations.
Example: Alarm scenario code snippet (TypeScript):
try {
vibrator.startVibration({
type: 'time',
duration: 1000,
}, {
id: 0,
usage: 'alarm'
}, (error: BusinessError) => {
if (error) {
console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`);
return;
}
console.info('Succeed in starting vibration.');
});
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error(`An unexpected error occurred. Code: ${e.code}, message: ${e.message}`);
}
You can find the related execution screnshot below;
Key Takeaways
- If the
usageisunknown,touch,media,physicalFeedback, orsimulateReality, vibration is controlled by the haptic feedback switch. - When the haptic feedback switch is enabled, vibration will occur even if the system is in silent mode.
- Input method (keyboard) applications usually manage vibration feedback independently. For better user experience, they are not affected by the system haptic feedback switch.

Top comments (0)