メインコンテンツまでスキップ
バージョン: v2

Haptics

The Haptics API provides physical feedback to the user through touch or vibration.

Android Notes

To use vibration, you must add this permission to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.VIBRATE" />

Example

import { Plugins, HapticsImpactStyle } from '@capacitor/core';

const { Haptics } = Plugins;

export class HapticsExample {
hapticsImpact(style = HapticsImpactStyle.Heavy) {
Haptics.impact({
style: style,
});
}

hapticsImpactMedium(style) {
this.hapticsImpact(HapticsImpactStyle.Medium);
}

hapticsImpactLight(style) {
this.hapticsImpact(HapticsImpactStyle.Light);
}

hapticsVibrate() {
Haptics.vibrate();
}

hapticsSelectionStart() {
Haptics.selectionStart();
}

hapticsSelectionChanged() {
Haptics.selectionChanged();
}

hapticsSelectionEnd() {
Haptics.selectionEnd();
}
}

API

impact(...)

impact(options: HapticsImpactOptions) => void

Trigger a haptics "impact" feedback

ParamType
options
HapticsImpactOptions

notification(...)

notification(options: HapticsNotificationOptions) => void

Trigger a haptics "notification" feedback

ParamType
options
HapticsNotificationOptions

vibrate()

vibrate() => void

Vibrate the device


selectionStart()

selectionStart() => void

Trigger a selection started haptic hint


selectionChanged()

selectionChanged() => void

Trigger a selection changed haptic hint. If a selection was started already, this will cause the device to provide haptic feedback


selectionEnd()

selectionEnd() => void

If selectionStart() was called, selectionEnd() ends the selection. For example, call this when a user has lifted their finger from a control


Interfaces

HapticsImpactOptions

PropType
style
HapticsImpactStyle

HapticsNotificationOptions

PropType
type
HapticsNotificationType

Enums

HapticsImpactStyle

MembersValue
Heavy"HEAVY"
Medium"MEDIUM"
Light"LIGHT"

HapticsNotificationType

MembersValue
SUCCESS"SUCCESS"
WARNING"WARNING"
ERROR"ERROR"