diff --git a/app/src/main/java/com/termux/api/VibrateAPI.java b/app/src/main/java/com/termux/api/VibrateAPI.java index 10f70e4..e37d729 100644 --- a/app/src/main/java/com/termux/api/VibrateAPI.java +++ b/app/src/main/java/com/termux/api/VibrateAPI.java @@ -2,6 +2,7 @@ package com.termux.api; import android.content.Context; import android.content.Intent; +import android.media.AudioManager; import android.os.Vibrator; import com.termux.api.util.ResultReturner; @@ -11,7 +12,15 @@ public class VibrateAPI { static void onReceive(TermuxApiReceiver apiReceiver, Context context, Intent intent) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); int milliseconds = intent.getIntExtra("duration_ms", 1000); - vibrator.vibrate(milliseconds); + boolean force = intent.getBooleanExtra("force", false); + + AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + if (am.getRingerMode() == AudioManager.RINGER_MODE_SILENT && !force) { + // Not vibrating since in silent mode and -f/--force option not used. + } else { + vibrator.vibrate(milliseconds); + } + ResultReturner.noteDone(apiReceiver, intent); }