diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 65e6a2b..076175a 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -16,6 +16,7 @@ import android.graphics.Color; import android.os.Build; import android.os.Handler; import android.os.IBinder; +import android.os.VibrationEffect; import android.os.Vibrator; import android.preference.PreferenceManager; import android.util.Log; @@ -175,7 +176,10 @@ public class TestService extends Service { int flags = 0; PendingIntent pendingIntent = PendingIntent.getActivity(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); - ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(2000);//バイブレーション + Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); + if (vibrator.hasVibrator()) { + vibrator.vibrate(VibrationEffect.createOneShot(2000, VibrationEffect.DEFAULT_AMPLITUDE)); + } @SuppressLint("NotificationTrampoline") NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "CHANNEL_ID") .setSmallIcon(android.R.drawable.ic_menu_info_details)