We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
The
VIBRATOR_SERVICE
variable is a variable in theContext
class.https://developer.android.com/reference/android/content/Context.html
Please check the ketai lib.
Kf
Thanks! I'm looking in to the library :)