开发者

Vibrator.vibrate() throws 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜