0

I've added vibration to my app and it never runs. I've definitely got the permission. This prints YAWP!!!

int x = PermissionChecker.checkSelfPermission(this, "android.permission.VIBRATE");
if (x != PermissionChecker.PERMISSION_GRANTED) {
    Log.d(TAG, "Vibrate? ACK!!!");
} else {
    Log.d(TAG, "Vibrate? YAWP!!!");
}

Here's my triggering code.

        Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE);
        if (v != null) {
            if (Build.VERSION.SDK_INT >= 26) {
                v.vibrate(VibrationEffect.createOneShot(1000, VibrationEffect.DEFAULT_AMPLITUDE));
            } else {
                v.vibrate(1000);
            }
        }

I've also tried:

    private void shakeItBaby() {
        // Get instance of Vibrator from current Context
        Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE);

// Output yes if can vibrate, no otherwise
        if (v.hasVibrator()) {
            Log.v("Can Vibrate", "YES");
        } else {
            Log.v("Can Vibrate", "NO");
        }

//        v.vibrate(VIBRATE_TIME);

        // Start without a delay
// Each element then alternates between vibrate, sleep, vibrate, sleep...
        long[] pattern = {0, 100, 1000, 300, 200, 100, 500, 200, 100};

// The '-1' here means to vibrate once, as '-1' is out of bounds in the pattern array
        v.vibrate(pattern, -1);

    }

I've tried answers from tons and tons of different questions, but nothing helps.

Ginger McMurray
  • 1,275
  • 2
  • 20
  • 42

1 Answers1

0

I was having the same problem and fixed it by changing Settings->Accessability->Vibration

Ian Hern
  • 641
  • 1
  • 8
  • 16