summaryrefslogtreecommitdiff
path: root/platform/android/java/src/org
diff options
context:
space:
mode:
authorvolzhs <volzhs@gmail.com>2019-08-18 00:27:29 +0900
committervolzhs <volzhs@gmail.com>2019-08-21 23:38:53 +0900
commit4061e5bb75cf4ad338cd077713946711cd7c70ea (patch)
treec5785dda4fffaf01ed6d751b9638dea62421d257 /platform/android/java/src/org
parent86371b7298e32356c8ce892f768c56bec7088292 (diff)
Support vibration for Android and iOS
Diffstat (limited to 'platform/android/java/src/org')
-rw-r--r--platform/android/java/src/org/godotengine/godot/Godot.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java
index 6e1841fa8b..b46cabae02 100644
--- a/platform/android/java/src/org/godotengine/godot/Godot.java
+++ b/platform/android/java/src/org/godotengine/godot/Godot.java
@@ -56,6 +56,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Messenger;
+import android.os.Vibrator;
import android.provider.Settings.Secure;
import android.support.v4.content.ContextCompat;
import android.view.Display;
@@ -98,6 +99,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
static final int MAX_SINGLETONS = 64;
static final int REQUEST_RECORD_AUDIO_PERMISSION = 1;
static final int REQUEST_CAMERA_PERMISSION = 2;
+ static final int REQUEST_VIBRATE_PERMISSION = 3;
private IStub mDownloaderClientStub;
private IDownloaderService mRemoteService;
private TextView mStatusText;
@@ -324,6 +326,15 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
});
}
+ 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);
+ }
+ }
+ }
+
public void restart() {
// HACK:
//
@@ -985,6 +996,13 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
return false;
}
}
+
+ if (p_name.equals("VIBRATE")) {
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.VIBRATE) != PackageManager.PERMISSION_GRANTED) {
+ requestPermissions(new String[] { Manifest.permission.VIBRATE }, REQUEST_VIBRATE_PERMISSION);
+ return false;
+ }
+ }
return true;
}