非推奨になったバイブレーション処理を置換

This commit is contained in:
ろむねこ 2024-07-11 14:27:52 +09:00
parent e77b50eee3
commit 8a4fa768a8
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168

View File

@ -16,6 +16,7 @@ import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.VibrationEffect;
import android.os.Vibrator; import android.os.Vibrator;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
@ -175,7 +176,10 @@ public class TestService extends Service {
int flags = 0; int flags = 0;
PendingIntent pendingIntent = PendingIntent.getActivity(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); 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") @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)