Skip to content

Commit

Permalink
termux-vibrate: Do not vibrate when in silent mode
Browse files Browse the repository at this point in the history
Do not vibrate when in silent mode unless the -f/--force option is
given.
  • Loading branch information
fornwall committed Jan 12, 2016
1 parent 7170f8d commit bf5dec5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/src/main/java/com/termux/api/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.AudioManager;
import android.os.Vibrator;

import com.termux.api.util.ResultReturner;
Expand All @@ -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);
}

Expand Down

0 comments on commit bf5dec5

Please sign in to comment.