From 11c55b3aebbcdf06e34c32a881e791371ab4178f Mon Sep 17 00:00:00 2001 From: joelJohanssonT Date: Tue, 19 Mar 2024 14:37:21 +0100 Subject: [PATCH] fix: deprication warning --- vibration/CHANGELOG.md | 2 +- .../com/benjaminabel/vibration/VibrationPlugin.java | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/vibration/CHANGELOG.md b/vibration/CHANGELOG.md index 4150a02..3946de3 100644 --- a/vibration/CHANGELOG.md +++ b/vibration/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.8.3 +## 1.8.4 - Added Web support (#95 by [san-smith](https://github.com/san-smith)) diff --git a/vibration/android/src/main/java/com/benjaminabel/vibration/VibrationPlugin.java b/vibration/android/src/main/java/com/benjaminabel/vibration/VibrationPlugin.java index d1bc19e..c72cd4d 100644 --- a/vibration/android/src/main/java/com/benjaminabel/vibration/VibrationPlugin.java +++ b/vibration/android/src/main/java/com/benjaminabel/vibration/VibrationPlugin.java @@ -1,7 +1,9 @@ package com.benjaminabel.vibration; import android.content.Context; +import android.os.Build; import android.os.Vibrator; +import android.os.VibratorManager; import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.BinaryMessenger; @@ -29,7 +31,13 @@ public void onAttachedToEngine(FlutterPluginBinding binding) { } private void setupChannels(BinaryMessenger messenger, Context context) { - final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); + Vibrator vibrator; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + VibratorManager vibratorManager = (VibratorManager) context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE); + vibrator = vibratorManager.getDefaultVibrator(); + } else { + vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); + } final VibrationMethodChannelHandler methodChannelHandler = new VibrationMethodChannelHandler(new Vibration(vibrator)); this.methodChannel = new MethodChannel(messenger, CHANNEL);