diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-08-27 17:42:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-27 17:42:32 +0200 |
commit | b7c46ed9298b6be4d61574979f686f59b8313be0 (patch) | |
tree | 360b3cb34f8c72f76f8feed9b119c2afb1a97bf0 /platform/android/java | |
parent | d3d6887e36808adcbf8c851f3dfc46c8fc88330c (diff) | |
parent | 8cda898fbb1df0900829d370beeafea00e16ac78 (diff) |
Merge pull request #31713 from volzhs/fix-vibrate
Suppress MissingPermission warning for Android vibration
Diffstat (limited to 'platform/android/java')
-rw-r--r-- | platform/android/java/src/org/godotengine/godot/Godot.java | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java index 7f71430805..1b3239777c 100644 --- a/platform/android/java/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/src/org/godotengine/godot/Godot.java @@ -31,6 +31,7 @@ package org.godotengine.godot; import android.Manifest; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.ActivityManager; import android.app.AlertDialog; @@ -56,6 +57,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Messenger; +import android.os.VibrationEffect; import android.os.Vibrator; import android.provider.Settings.Secure; import android.support.annotation.Keep; @@ -325,12 +327,18 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC * Used by the native code (java_godot_wrapper.h) to vibrate the device. * @param durationMs */ + @SuppressLint("MissingPermission") @Keep private void vibrate(int durationMs) { if (requestPermission("VIBRATE")) { Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { - v.vibrate(durationMs); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + v.vibrate(VibrationEffect.createOneShot(durationMs, VibrationEffect.DEFAULT_AMPLITUDE)); + } else { + //deprecated in API 26 + v.vibrate(durationMs); + } } } } |