デバイスをバイブレーションさせる処理を統一

This commit is contained in:
ろむねこ 2024-07-11 14:53:03 +09:00
parent 6a998d5718
commit aca3a15686
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168

View File

@ -145,9 +145,16 @@ public class TestService extends Service {
return PendingIntent.getActivity(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); return PendingIntent.getActivity(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE);
} }
private void vibrateDevice() {
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator.hasVibrator()) {
vibrator.vibrate(VibrationEffect.createOneShot(2000, VibrationEffect.DEFAULT_AMPLITUDE));
}
}
public void Notification(Context context) {//実際に通知を行うメソッド public void Notification(Context context) {//実際に通知を行うメソッド
((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(2000);//バイブレーション vibrateDevice();
@SuppressLint("NotificationTrampoline") NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) @SuppressLint("NotificationTrampoline") NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(android.R.drawable.ic_menu_info_details) .setSmallIcon(android.R.drawable.ic_menu_info_details)
@ -172,11 +179,7 @@ public class TestService extends Service {
if (ActivityCompat.checkSelfPermission(this, if (ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) return; android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) return;
vibrateDevice();
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator.hasVibrator()) {
vibrator.vibrate(VibrationEffect.createOneShot(2000, VibrationEffect.DEFAULT_AMPLITUDE));
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(android.R.drawable.ic_menu_info_details) .setSmallIcon(android.R.drawable.ic_menu_info_details)