gpt4 book ai didi

android - Vibrator.vibrate() 抛出 ArrayIndexOutOfBoundsException

转载 作者:太空狗 更新时间:2023-10-29 15:43:53 26 4
gpt4 key购买 nike

我使用以下代码 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com