0

I'm trying to find a usable haptic feedback code snippet that could be applied to a button click event.

The main aim is to have a slight vibration similar to typing on the keyboard.How would I code this in the click event.

Does anyone have a relevant implementation? Any examples that I've seen so far are bot suitable for this application as they are related to gaming.My api level is 18.

What I've tried so far is this solution from a previous question:

import android.view.View;
import android.os.Vibrator;

public class Main extends Activity implements OnClickListener
{
    private View myView;
    private Vibrator myVib;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        myVib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);

        //myView can be any type of view, button, etc.
        myView = (View) this.findViewById(R.id.myView);
        myView.setOnClickListener(this);
    }

    @Override
    public void onClick(View v)
    {
        myVib.vibrate(50);
        //add whatever you want after this
    }
}
Brian Var
  • 6,029
  • 25
  • 114
  • 212

0 Answers0