我正在尝试为 Android Vibration 制作本机扩展。我发现的每个开源扩展都只使用了vibrate(duration)
而不是vibrate(pattern, repeat)
andvibrate.cancel()
我需要能够传递模式和取消功能。
我可以毫无问题vibration(duration)
地正常工作。有一个简单的args[1].getAsInt();
方法供我使用。但是,没有.getAsArray
or .getAsLong
。
我发现了一个叫做 FREArray 的东西,但我真的不明白如何使用它。
所以,我的问题是,我可以通过一个 AS3 函数传递一个数组(带有模式)和一个 int(用于重复计数)我如何在 Android 端接收数组?我在接收重复的 int 时没有任何问题。
到目前为止,这是我一直在使用的东西,但是由于错误,我看起来好像没有正确使用它。有什么建议么?
public FREObject call(FREContext context, FREObject[] args) {
VibrateExtensionContext vibrate(pattern, repeat)ExtensionContext) context;
long[] pattern;
int repeat = 0;
try {
pattern = FREArray.newArray(args[0]); //this is where im stuck
//it would be ideal if there was something like this..
//pattern = args[0].getAsLong(); but this doesnt exist
repeat = args[1].getAsInt(); //this works fine
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FRETypeMismatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FREInvalidObjectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FREWrongThreadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
vibExtContext.androidVibrator.vibrate(pattern, repeat);
return null;
}