Start stop vibrate

anaylor01

Well-Known Member
Licensed User
Longtime User
I know the code to start vibrate but how do you stop it. I tried issuing another vibrate command of vibrate1.vibrate(0) but it doesn't stop it.
 

genesi

Active Member
Licensed User
Longtime User
That is how I start it but how do I stop it?

I have found this code by Erel
B4X:
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
i hope you helpful
Mario
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
That looks good. But I do not know what this is and it is giving me an error.
Dim r As Reflector
Is there a library I need to add?
 
Upvote 0
Top