Android - Vibration device not working

Actually, I have an application that I am testing using two devices. One LG GW620 and one Samsung Spica. I would like the user to touch the screen, the device vibrates.

In fact, on the LG GW620, the device vibrates when I touch it. But not at the back ...

I was looking for settings on spica, but Vibrator checks, so I do not understand why it does not vibrate.

In my application, I have: <uses-permission android:name="android.permission.VIBRATE"></uses-permission>

and in code:

 Vibrator vibrator =(Vibrator)getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(100); 

But I think this is not the best thing. I want the device to vibrate for every click, but I donโ€™t know if I need to make a vibrator for every OnClick? Or if I can only make one vibrator for the entire application?
And especially why it doesn't work on Spica?

+6
android
source share
2 answers

Are funny. In your onClick button you have to put the vibration. And since in milliseconds I would put something like 500 for half a second, and not for 0.1 seconds.

 void onCreate() { mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); Button b = (Button) findViewById(R.id.button); b.setOnClickListener(new View.OnClickListener() { void onClick() { mVibrator.vibrate(500); } }); } 
+4
source share

Almost all solutions on the Internet seem to be missing something., (Context) is a working solution,.

  Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(100); 
0
source share

All Articles