Sunday, December 23, 2018

Front End Code for Android Vibration

$*#@%$ ca-app-pub-7559147661361211/9236747806

To vibrate a phone we need following Permission Do not forget to declare this permission in Manifest.

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

We can Vibrate a Phone Using an Activity  , Service and Using Threads.

Using Activity will not be a good Idea because it takes time to vibrate the Phone and an Activity always runs in foreground.

We will implement using Service because  a Service runs in Background.

for we need to have an Object of Class Vibrator, we do not create the Object directly but we get Vibrate System Service.

Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);

Add    <uses-permission android:name="android.permission.VIBRATE"/>  in Your Manifest

Code to Vibrate the Phone

Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);

                                     // pass the number of millseconds fro which you want to vibrate the phone here we
                                     // have passed 2000 so phone will vibrate for 2 seconds.


                                   // If you want to vibrate  in a pattern
                                   //  long pattern[]={0,800,200,1200,300,2000,400,4000};
                                   // 2nd argument is for repetition pass -1 if you do not want to repeat the Vibrate
                                   // v.vibrate(pattern,-1);


  1. What's up colleagues, nice post and pleasant arguments commented here, I am
    really enjoying by these.

  2. excellent submit, very informative. I'm wondering why the
    other experts of this sector don't notice this.
    You must proceed your writing. I'm confident, you've a huge
    readers' base already!

  3. Good post. I learn something totally new and challenging on blogs I stumbleupon every day.
    It's always exciting to read through content from other writers and practice something from other web sites.

  4. Great goods from you, man. I've consider your stuff prior to and you're simply too wonderful.
    I actually like what you have got right here, really like what you are stating and the way during which you are saying it.
    You make it enjoyable and you continue to take care of to keep it sensible.
    I can not wait to learn much more from you. This is really a tremendous website.