开发者

Basic4Android Vibration pattern

I'm trying to create an application that have different vibration patterns.

I've seen that the PhoneVibrate class has only a Vibrate(TimeMs as Long) function. I've also seen that there also is another java function that supports patterns (see here: http://mobile.tutsplus开发者_如何学JAVA.com/tutorials/android/android-vibrator/ )

Is it possible to use it on Basic4Android? How do I solve this problem? Regards,

Nicola


You can use this code (requires Phone library and Reflection library):

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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜