Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Vibrate Phone programmatically

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 174
    Comment on it

    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.

    1. public class MainActivityVibrator extends Activity {
    2. public Vibrator vib;
    3.  
    4. @Override
    5. protected void onCreate(Bundle savedInstanceState)
    6. {
    7. super.onCreate(savedInstanceState);
    8. setContentView(R.layout.activity_main);
    9. }
    10.  
    11. public void onStartVibrationOnClick(View v)
    12. {
    13.  
    14. //Set the pattern for vibration
    15. long pattern[]={0,200,300,400,400};
    16.  
    17. //Start the vibration
    18. vib = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
    19.  
    20. vib.vibrate(pattern, 0);
    21. }
    22.  
    23. //Stop vibration
    24. public void onStopVibrationOnClick(View v)
    25. {
    26. vib.cancel();
    27. }}

    add this permission in your manifest file :

    1. <uses-permission android:name="android.permission.VIBRATE"/>

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: