$*#@%$ ca-app-pub-4111868940087848/3418151202
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
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.
v.vibrate(2000);
// 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);
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.
v.vibrate(2000);
// 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);