Haptic Feedback on Android

Trying to figure out how to get an android device to vibrate.
I do this on iOS with declares.

little help?

i found this about in case xojo not offer vibrate.

How to vibrate Android device || Android studio tutorial

https://youtu.be/02xNGQOCOTs?si=d3o2gp8LD6Yn_VIi

Yes I’ve done this in AS.
It’s one of the last things I need to complete my first Xojo Android project.

Does that work for you:

  1. Add this to the Android Build Settings Manifest Permissions: android.permission.VIBRATE
  2. Use this Code:
Declare Sub import Lib "android.os.*:Import"

Declare Function vibrator Lib "android.content.Context.Instance:Kotlin" Alias _
  "getSystemService(android.content.Context.VIBRATOR_SERVICE)" _
  (context As Ptr) As Ptr

Declare Function createOneShot Lib "Kotlin" Alias _
  "VibrationEffect.createOneShot(durationmillis.toLong(), VibrationEffect.DEFAULT_AMPLITUDE)" _
  (durationMillis As Int64) As Ptr

Declare Sub vibrate Lib "android.os.Vibrator.Instance:Kotlin" Alias _
  "vibrate(effect as VibrationEffect)" _
  (ref As Ptr, effect As Ptr)

Var oVibrator As Ptr = vibrator(App.AndroidContextHandle)
Var oEffect As Ptr = createOneShot(200)

vibrate(oVibrator, oEffect)
2 Likes

Sure does!

Thank you very much!

1 Like