Skip to content

Commit

Permalink
Fixed: Fix vibration not happening if duration is under 1000ms and to…
Browse files Browse the repository at this point in the history
…uch vibration is disabled

Fix source: https://stackoverflow.com/a/62839808/14686958

Closes #666
  • Loading branch information
agnostic-apollo committed Mar 19, 2024
1 parent e994de5 commit a9abc96
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/com/termux/api/apis/VibrateAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.Intent;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.os.Build;
import android.os.VibrationEffect;
Expand Down Expand Up @@ -30,11 +31,16 @@ public void run() {
Logger.logError(LOG_TAG, "Audio service null");
return;
}
// Do not vibrate if in silent mode and -f/--force option is not used.

// Do not vibrate if "Silent" ringer mode or "Do Not Disturb" is enabled and -f/--force option is not used.
if (am.getRingerMode() != AudioManager.RINGER_MODE_SILENT || force) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
vibrator.vibrate(VibrationEffect.createOneShot(milliseconds, VibrationEffect.DEFAULT_AMPLITUDE));
vibrator.vibrate(VibrationEffect.createOneShot(milliseconds, VibrationEffect.DEFAULT_AMPLITUDE),
new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ALARM)
.build());
} else {
vibrator.vibrate(milliseconds);
}
Expand Down

0 comments on commit a9abc96

Please sign in to comment.