Wednesday, January 30, 2019
Vibration adds a nice feel to your device, it makes the user feel part of your app and awaken. I am going to show you how to make your phone vibrate when you long press a button.
1. import the vibrate class
2. next, this will be the code that will listen for a long press, and make your phone vibrate.
Note: this will make your phone vibrate for 100 milliseconds, hence 1000ms is 1s
enjoy this nice feature.
1. import the vibrate class
import android.os.Vibrator;
2. next, this will be the code that will listen for a long press, and make your phone vibrate.
button.setOnLongClickListener(new View.OnLongClickListener(){ @Override public boolean onLongClick(View v) {Vibrator vibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(100); return true; } });
Note: this will make your phone vibrate for 100 milliseconds, hence 1000ms is 1s
enjoy this nice feature.