【问题标题】:Android: phone ignores correct vibration codeAndroid:手机忽略正确的振动代码
【发布时间】:2014-11-07 19:47:19
【问题描述】:

设置。 我想让我的手机在点击按钮时振动。我使用SO question: How to make an Android device vibrate?的代码。

让手机振动的代码:

@Override
public void onClick (View view)
{
    Vibrator vibrator = (Vibrator) MyActivity.this.getSystemService (Context.VIBRATOR_SERVICE);

    if (vibrator.hasVibrator()) {
        Log.v ("Can Vibrate", "YES");
    } else {
        Log.v("Can Vibrate", "NO");
    }
        vibrator.vibrate (1000);
    }

我也添加了权限

<uses-permission android:name="android.permission.VIBRATE"/>

到清单文件。

问题。 单击按钮时手机根本不会振动。我手机上的其他应用程序会使手机振动。

记录消息。

xxxx V/Can Vibrate﹕ YES
xxxx V/Vibrator﹕ Called vibrate(long) API - PUID: 10060, PackageName: de.creamin.vibratetest
xxxx V/Vibrator﹕ vibrate - PUID: 10060, PackageName: de.creamin.vibratetest, ms: 1000, mag: -1

电话。 三星 Galaxy S3 (GT-I9300),Android 4.3

问题。这是怎么回事?我是否必须以某种方式配置我的手机才能接受振动码?

【问题讨论】:

    标签: android android-vibration


    【解决方案1】:

    我找到了我的手机不振动的原因。在菜单项下

    phone settings &gt; My device &gt; Sound &gt; Vibration intensity

    您可以调整Incoming callNotificationHaptic feedback 的振动强度。 Notification 的设置已设置为零。因此,我的手机没有振动。将该滑块设置为大于零的值后,我的手机会在单击应用中的按钮时振动。

    【讨论】:

      【解决方案2】:

      无需传递 MyActivity。这可能是。试试:

      Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE)
      

      【讨论】:

      • 我试过了,但行为没有改变。手机仍然没有振动。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-10
      • 1970-01-01
      • 2019-12-22
      • 1970-01-01
      • 1970-01-01
      • 2013-01-28
      • 2020-05-10
      相关资源
      最近更新 更多