1
0
mirror of https://github.com/danog/termux-api.git synced 2024-11-30 04:19:20 +01:00

termux-vibrate: Do not vibrate when in silent mode

Do not vibrate when in silent mode unless the -f/--force option is
given.
This commit is contained in:
Fredrik Fornwall 2016-01-12 14:13:01 +01:00
parent 7170f8dcde
commit bf5dec5c0d

View File

@ -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);
}