如何获取 android 设备的默认振动模式?

how to get the default vibration pattern of an android device?

我正在为 Android API 23 创建一个应用程序,我想获取 phone 响铃时使用的默认振动模式?

到目前为止我有这个:

Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
long[] pattern = {0, 500, 1000}; // default pattern goes here
vibrator.vibrate(pattern, 0);

如何获取默认模式?

据我所知,默认振动模式是

{ delay, vibrate, sleep, vibrate, sleep } pattern

如果是你的代码

long[] pattern = new long[] { 1000, 1000, 1000, 1000, 1000 };

振动现在设置为延迟 1000 毫秒。如果您将第一个设置为 0,它会立即熄灭。

默认震动模式可以在下面class找到:com/android/server/notification/NotificationManagerService.java,也就是

static final long[] DEFAULT_VIBRATE_PATTERN = {0, 250, 250, 250};

查看来自 here 的源代码。

遗憾的是,目前还没有 public API 获得此默认模式。