Basic4Android振动模式

时间:2011-10-16 09:45:24

标签: design-patterns vibrate vibration basic4android

我正在尝试创建一个具有不同振动模式的应用程序。

我已经看到PhoneVibrate类只有一个Vibrate(TimeMs as Long)函数。 我还看到还有另一个支持模式的java函数 (见这里:http://mobile.tutsplus.com/tutorials/android/android-vibrator/

是否可以在Basic4Android上使用它?我该如何解决这个问题? 的问候,

尼古拉

1 个答案:

答案 0 :(得分:1)

您可以使用此代码(需要电话库和反射库):

Sub Process_Globals
    Dim pv As PhoneVibrate 'Required to add the Vibrate permission
End Sub

Sub Globals

End Sub
Sub Activity_Create(FirstTime As Boolean)
    Vibrate(500, 300)
    ToastMessageShow("Click anywhere to stop vibrate.", True)
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Activity_Resume

End Sub

Sub Activity_Click
    CancelVibrate
End Sub

Sub Vibrate(On As Long, Off As Long)
    Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "vibrator", "java.lang.String")
    Dim pattern(2) As Long
    pattern(0) = On
    pattern(1) = Off
    r.RunMethod4("vibrate", Array As Object(pattern, 0), Array As String("[J", "java.lang.int"))
End Sub

Sub CancelVibrate
    Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "vibrator", "java.lang.String")
    r.RunMethod("cancel")
End Sub