Vibrations in Processing for Android

So I’ve been trying to make my phone vibrate when the screen is clicked, but it’s not working. I’ve checked the sketch premissions too. Thank you for your help. The code that isn’t working

import android.content.Context;
import android.os.Build;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.os.VibratorManager;

Vibrator vibrator;

void setup() {
  fullScreen();
  
  VibratorManager vibratorManager = (VibratorManager) getActivity().getSystemService(Context.VIBRATOR_MANAGER_SERVICE);
  vibrator = vibratorManager.getDefaultVibrator();
  println("vibrating");
  vibrator.vibrate(VibrationEffect.createOneShot(1000, VibrationEffect.DEFAULT_AMPLITUDE));
}

void draw() {
  background(0);
  fill(255);
  textAlign(CENTER, CENTER);
  text("Touch the screen to vibrate", width / 2, height / 2);
}

void touchStarted() {
  vibrator.vibrate(VibrationEffect.createOneShot(1000, VibrationEffect.DEFAULT_AMPLITUDE));
  println("vibrating");
}

The following source code will cause an old Nexus phone to vibrate. It has no effect on a tablet because I’m not sure they have that feature. Make sure ‘vibrate on touch’ is turned on in the phone’s settings and the sketch’s permissions is set to ‘Vibrate’. You may not need all those imports; I didn’t test which ones are used. Note that VIBRATOR_SERVICE is marked as deprecated, but it still works.

//https://stackoverflow.com/questions/45605083/android-vibrate-is-deprecated-how-to-use-vibrationeffect-in-android-api-26
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.VibrationEffect;
import android.os.VibrationAttributes;
import android.os.VibrationAttributes.Builder;
import android.os.Vibrator;
import android.os.VibratorManager;
import android.os.Build;

void shakeIt() {
    if (Build.VERSION.SDK_INT >= 26) {
      println("sdk > 26");
        ((Vibrator) this.getContext().getSystemService(Context.VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(150,10));
    } else {
      println("sdk < 26");
        ((Vibrator) this.getContext().getSystemService(Context.VIBRATOR_SERVICE)).vibrate(1000);
    }
}

void setup() {
  fullScreen();
}

void draw() {
  background(0);
  fill(255);
  textSize(100);
  textAlign(CENTER, CENTER);
  text("Touch the screen to vibrate", width / 2, height / 2);
}

void touchStarted(){
  shakeIt();
}