开发者

Vibrator.vibrate() throws ArrayIndexOutOfBoundsException

开发者 https://www.devze.com 2023-02-09 11:12 出处:网络
I use the following snippet to vibrate the phone in a specific pattern, but it throws and ArrayIndexOutOfBoundsException.

I use the following snippet to vibrate the phone in a specific pattern, but it throws and ArrayIndexOutOfBoundsException.

vibrator.vibrate(new long[] { selectedDuration, CONSTANT开发者_JS百科_DELAY }, REPEAT); 

But

vibrator.vibrate(VIBRATE_DURATION);

works fine. Any pointers?


The docs say:

If you want to repeat, pass the index into the pattern at which to start the repeat.

Means REPEAT is only allowed to be 0 or 1 in your case.

This is the implementation:

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();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号