From 3178dee53c60a00ab7e0620eef7e0d1cdea998b1 Mon Sep 17 00:00:00 2001 From: volzhs Date: Tue, 27 Aug 2019 21:52:44 +0900 Subject: [PATCH] Suppress MissingPermission warning for Android vibration It does check its permission every `vibrate_handheld()` calls. Vibrate permission is added by checking it on export settings. And there are some changes for deprecated method. --- .../android/java/src/org/godotengine/godot/Godot.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java index b058a6f3da8..01aa76e0c2d 100644 --- a/platform/android/java/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/src/org/godotengine/godot/Godot.java @@ -32,6 +32,7 @@ package org.godotengine.godot; //import android.R; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.ActivityManager; import android.app.AlertDialog; @@ -58,6 +59,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.v4.content.ContextCompat; @@ -330,11 +332,17 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC }); } + @SuppressLint("MissingPermission") public void vibrate(int p_duration_ms) { if (requestPermission("VIBRATE")) { Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { - v.vibrate(p_duration_ms); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + v.vibrate(VibrationEffect.createOneShot(p_duration_ms, VibrationEffect.DEFAULT_AMPLITUDE)); + } else { + //deprecated in API 26 + v.vibrate(p_duration_ms); + } } } }