How to make the phone vibrate

edited March 2018 in Android Mode

Hello everyone,

I'm making a minesweeper game and when the player presses the mouse/finger down for long enough, you can place a marker. I want to make the phone vibrate when you have pressed down for long enough.

I searched on the internet quite a while and the only thing ive found is this code but i get the error: The variable "VIBRATOR_SERVICE" does not exist.

Can anyone please help me with this?

Here is my code:

import android.app.Activity; import android.content.Context; import android.os.Vibrator; import android.os.Build; void touchEnded() { if (Build.VERSION.SDK_INT >= 26) { ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(150,10)); } else { ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(150); } }

Answers

Sign In or Register to comment.