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
    • 168
    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.

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: