6

我实际上有一个我用两台设备测试的应用程序。一台LG GW620,一台三星Spica。我想当用户触摸屏幕时,设备会振动。

事实上,在 LG GW620 上,当我触摸它时设备会振动。但在角宿不...

我在 spica 上寻找设置,但振动器已检查,所以我不明白为什么它不振动。

在我的应用程序中,我有:<uses-permission android:name="android.permission.VIBRATE"></uses-permission>

并在代码中:

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

但我认为这样做并不是最好的。我希望设备在每次点击时振动,但我不知道我是否必须为每次 OnClick 做一个振动器?或者如果我只能为所有应用程序做一个振动器?
尤其是为什么它在 Spica 上不起作用?

4

2 回答 2

4

有趣的。在您的 onClick 按钮中,您应该放置振动。而且因为它是以毫秒为单位的,所以我会在半秒内输入 500 而不是 0.1 秒。

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);
        }
    });
}
于 2010-06-24T12:12:44.627 回答
0

互联网上几乎所有的解决方案似乎都缺少一些东西。. (上下文)这是一个可行的解决方案。. .

    Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(100);
于 2017-09-12T08:38:18.247 回答