Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

vibration - Android - Vibrating device doesn't work

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);
        }
    });
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...