how to do haptic feedback when an ImageView is not working

2.1k views Asked by At

I created an Activity displays an ImageView on the screen. I want get haptic feedback when the image is clicked.

In the main layout main.xml I added the next ImageView tag:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/image"
    android:src="@drawable/dog"
    android:onClick="doBark"
    android:hapticFeedbackEnabled="true"/>

Then, in the Activity code I add this method:

public void doBark(View v) {
        v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
        Log.d("BarkingDog", "is hapticFeedbackEnabled: " + v.isHapticFeedbackEnabled());
}

When I click on the image I can see that doBark() is called and the output of the Logcat says "is hapticFeedbackEnabled: true", but I can't feel anything. I've also tried with the other two HapticFeedback constants, and no luck.

I know that HapticFeedback is enabled because each time I press the menu button, the device vibrates.

Any ideas? Suggestions?

PS: I don't want to use the Vibrator object. By using it, I can make the device vibrate, but I don't think it's the right way to do it.

0

There are 0 answers