【问题标题】:Will Vibrator.vibrate throw an error if the device can't vibrate?如果设备不能振动,Vibrator.vibrate 会报错吗?
【发布时间】:2023-03-08 21:53:01
【问题描述】:

我希望不是,但只是想得到一个明确的答案,因为它没有在文档中说明。振动前是否需要检查 Vibrate.hasVibrator?

【问题讨论】:

  • 只用没有震动的设备运行模拟器?
  • 为什么不先检查?这样,如果您不能振动,您就会知道并且可以(如果这样做是明智的)使用其他方法通知设备用户。

标签: android-vibration


【解决方案1】:

根据android.os.Vibrator的源码,vibrate()不会抛出任何东西:

public void vibrate(long milliseconds)
{
    try {
        mService.vibrate(milliseconds, mToken);
    } catch (RemoteException e) {
    }
}

【讨论】:

  • 也不会取消()!谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多