In Android you can also use vibration method of android. There is an abstract class named Vibrator that helps you to implement vibrations in your own applications.
method vibrate will vibrate with a given pattern.
public class MainActivityVibrator extends Activity {
public Vibrator vib;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onStartVibrationOnClick(View v)
{
//Set the pattern for vibration
long pattern[]={0,200,300,400,400};
//Start the vibration
vib = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
vib.vibrate(pattern, 0);
}
//Stop vibration
public void onStopVibrationOnClick(View v)
{
vib.cancel();
}}
add this permission in your manifest file :
<uses-permission android:name="android.permission.VIBRATE"/>
0 Comment(s)