Android - Vibrating device doesn't work

后端 未结 2 2095
没有蜡笔的小新
没有蜡笔的小新 2020-12-19 07:53

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 t

相关标签:
2条回答
  • 2020-12-19 08:43

    Almost all solutions on the internet seem to missing something . . (context) heres a working solution . . .

        Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(100);
    
    0 讨论(0)
  • 2020-12-19 08:55

    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);
            }
        });
    }
    
    0 讨论(0)
提交回复
热议问题