如何获得Android设备的默认振动模式?

时间:2016-06-14 07:01:26

标签: android android-6.0-marshmallow android-vibration

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

到目前为止,我有这个:

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

如何获得默认模式?

2 个答案:

答案 0 :(得分:6)

默认振动模式可在以下课程中找到:com/android/server/notification/NotificationManagerService.java,即

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

请参阅here的源代码。

不幸的是,到目前为止还没有公共API来获取此默认模式。

答案 1 :(得分:-3)

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

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

如果您的代码

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

振动现在设定为1000毫秒的延迟。如果您将第一个设置为0,它将立即关闭。

相关问题