我使用以下代码 fragment 以特定模式振动手机,但它抛出 ArrayIndexOutOfBoundsException。
vibrator.vibrate(new long[] { selectedDuration, CONSTANT_DELAY }, REPEAT);
但是
vibrator.vibrate(VIBRATE_DURATION);
工作正常。有什么指点吗?
最佳答案
文档说:
If you want to repeat, pass the index into the pattern at which to start the repeat.
表示在您的情况下 REPEAT 只允许为 0 或 1。
这是实现:
public void vibrate(long[] pattern, int repeat)
{
// catch this here because the server will do nothing. pattern may
// not be null, let that be checked, because the server will drop it
// anyway
if (repeat < pattern.length) {
try {
mService.vibratePattern(pattern, repeat, mToken);
} catch (RemoteException e) {
}
} else {
throw new ArrayIndexOutOfBoundsException();
}
}
关于android - Vibrator.vibrate() 抛出 ArrayIndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4915382/