Android Vibrate on touch?
please try this :
Button b = (Button) findViewById(R.id.button1);
b.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Vibrator vb = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vb.vibrate(100);
return false;
}
});
and add this permission to manifest.xml
<uses-permission android:name="android.permission.VIBRATE"/>
According to this answer, you can perform haptic feedback (vibrate) without asking for any extra permissions. Look at performHapticFeedback
method.
View view = findViewById(...)
view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Note: I have not tested this code.