views:

133

answers:

1

Hi all,
I actually have an app that I test with two devices. One LG GW620, and one Samsung Spica. I would like when User touch the screen, the device vibrate.

In fact, On the LG GW620, the device vibrate when I touch it. But on the spica doesn't...

I looked for settings on the spica, but Vibrator is check, so I don't understand why it doesn't vibrate.

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

and in the code :

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

But I think it is not the best thing to do that. I wish device vibrate for every click, but I don't know if I have to do a Vibrator for each OnClick ? Or if I could do only one Vibrator for all the application ?
And especially why it doesn't work on Spica ?

+2  A: 

Funny. In your onClick for the button you should put the vibrate. And since it is in miliseconds I'd put something like 500 for half a second instead of .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);
        }
    });
}
BrennaSoft
ok, so I must do that for each buttons/ImageView of my application ? there is no other way ? Because I have 30 or 40 Buttons on my app so it will be very long.
Nanis
If you are using the 1.6 SDK (version 4), Views can have an onClick method set in the xml. So for each button you could set the onClick, and in your activity the method must have a signiature matching onClick(View v) where v will be the button clicked.For each button set android:onClick="onClick" where onClick is the name of the onClick method in your Activity.http://developer.android.com/reference/android/R.attr.html#onClick
BrennaSoft
Thx a lot for your answer, this is helpful. Do you have any idea why Spica doesn't vibrate whereas LG GW620 do ??
Nanis
No. Maybe try to increase the time to 500 instead of 100. Maybe it vibrated so quickly you didn't notice haha.
BrennaSoft
At the beggining I put 1 sec lol, It was very very long. 100ms is good, on the LG there is no problem.
Nanis