Android Question Using B4A. How to I get haptic feedback when a button is pressed?

BillMeyer

Well-Known Member
Licensed User
Longtime User
This should do the trick:

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim vib As PhoneVibrate
    Dim but1 As button
   
End Sub

Sub but1_Click
    vib.vibrate
    'do here what you need to with this button  
End Sub
(Untested - Out of my head coding)

Enjoy !!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Paulo Rosa

Member
Licensed User
Source: https://www.b4x.com/android/forum/t...g-a-cross-platform-tetris-game.94212/#content

B4A and B4i code:
B4X:
Private Sub PerformHapticFeedback (view As Object)
   #if B4A
   Dim jo As JavaObject = view
   jo.RunMethod("performHapticFeedback", Array(1))
   #Else if B4i
   FeedbackGenerator.RunMethod("impactOccurred", Null) 'see the tetris example
   #end if
End Sub

Hi Erel,

How can I use this code if the view is a widget image, for instance? I mean, I would like to perform haptic feedback when an image of a widget is pressed.

Regards,
 
Upvote 0
Top