[TinyTut] - Android VibratorService
What you learn: You will learn how to use Androids VibratorService.
Difficulty: 1 of 5

Description:
Vibration is also as easy as the most things on the Android-Platform
What we need to do are 2 simple things:
- Get the Service, that is responsible for Vibration.
- Call myVibratorService.vibrate(int) .
Sample Activity:
Using java Syntax Highlighting
- public class AndroidVibrator extends Activity {
- android.os.IVibratorService myVibratorService = null;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(R.layout.main);
- // Receive the VibratorManagerService
- myVibratorService = android.os.IVibratorService.Stub
- .asInterface(ServiceManager.getService("vibrator"));
- // Do a short (100ms) vibration.
- try {
- myVibratorService.vibrate(100);
- } catch (DeadObjectException e) { }
- }
- }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
For continuous vibration you could write the following:
Using java Syntax Highlighting
- new Thread(){
- @Override
- public void run(){
- try {
- while(!isInterrupted()){
- myVibratorService.vibrate(500);
- Thread.sleep(1000);
- }
- } catch (Exception e) { }
- }
- }.start();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
Do not forget to interrupt the Thread somewhen

This is the output you can see in the LogCat:
Using java Syntax Highlighting
- I/Vibrator(484): off
- I/Vibrator(484): on
- I/Vibrator(484): off
- I/Vibrator(484): on
- ...
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
Regards,
plusminus




i wish i can quit my day job and doing Android stuff all day long... daily work sux big time...

Katharnavas,
Would be a really nice feature.
