// Get instance of Vibrator from current Context Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Output yes if can vibrate, no otherwise if (v.hasVibrator()) { Log.v("Can Vibrate", "YES"); } else { Log.v("Can Vibrate", "NO"); }
@Override public boolean isPeripheralAvailable (Peripheral peripheral) { if (peripheral == Peripheral.Accelerometer) return accelerometerAvailable; if (peripheral == Peripheral.Gyroscope) return gyroscopeAvailable; if (peripheral == Peripheral.Compass) return compassAvailable; if (peripheral == Peripheral.HardwareKeyboard) return keyboardAvailable; if (peripheral == Peripheral.OnscreenKeyboard) return true; if (peripheral == Peripheral.Vibrator) { if (Build.VERSION.SDK_INT >= 11) { return vibrator != null && vibrator.hasVibrator(); } else { return vibrator != null; } } if (peripheral == Peripheral.MultitouchScreen) return hasMultitouch; if (peripheral == Peripheral.RotationVector) return rotationVectorAvailable; if (peripheral == Peripheral.Pressure) return true; return false; }
@Override public boolean isPeripheralAvailable (Peripheral peripheral) { if (peripheral == Peripheral.Accelerometer) return accelerometerAvailable; if (peripheral == Peripheral.Gyroscope) return gyroscopeAvailable; if (peripheral == Peripheral.Compass) return compassAvailable; if (peripheral == Peripheral.HardwareKeyboard) return keyboardAvailable; if (peripheral == Peripheral.OnscreenKeyboard) return true; if (peripheral == Peripheral.Vibrator) { if (Build.VERSION.SDK_INT >= 11) { return vibrator != null && vibrator.hasVibrator(); } else { return vibrator != null; } } if (peripheral == Peripheral.MultitouchScreen) return hasMultitouch; if (peripheral == Peripheral.RotationVector) return rotationVectorAvailable; if (peripheral == Peripheral.Pressure) return true; return false; }
String vs = Context.VIBRATOR_SERVICE; Vibrator mVibrator = (Vibrator)getSystemService(vs); boolean isVibrator = mVibrator.hasVibrator();
@TargetApi(HONEYCOMB) public VibratorAssert hasNoVibrator() { isNotNull(); Assertions.assertThat(actual.hasVibrator()) // .overridingErrorMessage("Expected to not have vibrator but did.") // .isFalse(); return this; } }
@TargetApi(HONEYCOMB) public VibratorAssert hasVibrator() { isNotNull(); Assertions.assertThat(actual.hasVibrator()) // .overridingErrorMessage("Expected to have vibrator but did not.") // .isTrue(); return this; }
@Test public void hasVibrator() { assertThat(vibrator.hasVibrator()).isTrue(); shadowOf(vibrator).setHasVibrator(false); assertThat(vibrator.hasVibrator()).isFalse(); }
Vibrator vi; vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); if(vi.hasVibrator()){ vi.vibrate(100); }
if (android.os.Build.VERSION.SDK_INT >= 11) { Vibrator v = (Vibrator) RunnerJNILib.ms_context.getSystemService(Context.VIBRATOR_SERVICE); return ((v.hasVibrator()) ? 1 : 0); } else { return 1; }
public static void handleVibration(Context context) { if(context == null) return; Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (!vibrator.hasVibrator()) return; //Check if we should vibrate boolean vibrateOnPress = PreferenceManager .getDefaultSharedPreferences(context) .getBoolean(Settings.KEY_PREF_VIBRATE_REMOTE_BUTTONS, Settings.DEFAULT_PREF_VIBRATE_REMOTE_BUTTONS); if (vibrateOnPress) { vibrator.vibrate(UIUtils.buttonVibrationDuration); } }
@SuppressLint("MissingPermission") private void playVibrateEffect() { if (Compat.checkSelfPermission(context, Manifest.permission.VIBRATE) == PackageManager.PERMISSION_DENIED) return; if (vibrator != null && vibrator.hasVibrator()) vibrator.vibrate(mVibrateMilliseconds); }
private void stopVibrate(Context context, Intent intent) { final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (!vibrator.hasVibrator()) { Toast.makeText(context, R.string.vibrator_not_found, Toast.LENGTH_LONG).show(); return; } vibrator.cancel(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(ToggleVibratePhone.NOTIFICATION_ID); vibrating=false; } }
/** * Whether the device hardware has a vibrator. */ private boolean hasVibrator() { Vibrator vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); return vibrator != null && vibrator.hasVibrator(); }
private void playVibrateEffect() { if (Compat.checkSelfPermission(context, Manifest.permission.VIBRATE) == PackageManager.PERMISSION_DENIED) return; if (vibrator != null && vibrator.hasVibrator()) vibrator.vibrate(mVibrateMilliseconds); }
private void invokeVibrate(long[] vibratePattern) { if (vibrator.hasVibrator() && Preferences.getAppLockVibrate()) { vibrator.vibrate(vibratePattern, -1); } } }
@TargetApi(HONEYCOMB) public VibratorAssert hasNoVibrator() { isNotNull(); Assertions.assertThat(actual.hasVibrator()) // .overridingErrorMessage("Expected to not have vibrator but did.") // .isFalse(); return this; } }
@TargetApi(HONEYCOMB) public VibratorAssert hasVibrator() { isNotNull(); Assertions.assertThat(actual.hasVibrator()) // .overridingErrorMessage("Expected to have vibrator but did not.") // .isTrue(); return this; }
private void dragPointer(MotionEvent event) { LimboActivity.vmexecutor.onLimboMouse(Config.SDL_MOUSE_LEFT, MotionEvent.ACTION_DOWN, 1, 0, 0); Vibrator v = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); if (v.hasVibrator()) { v.vibrate(100); } }
private Vibrator getVibrator() { if (mLastInputDevice != null) { Vibrator vibrator = mLastInputDevice.getVibrator(); if (vibrator.hasVibrator()) { return vibrator; } } return (Vibrator)getContext().getSystemService(Context.VIBRATOR_SERVICE); }
@Override public void onLongPress(MotionEvent e) { Vibrator vibe = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE); if (vibe.hasVibrator()) { vibe.vibrate(20); } setZoom(getMaxZoomOut()); setOffset(0, false); refreshGraph(); }