私は通知を使ってアプリを書いています。Google 開発者ガイドラインでは、開発者が通知をカスタマイズするための設定 (バイブレーションを無効にする、通知音を設定するなど) を提供することを推奨しているため、ユーザーがそのように設定した場合、通知のバイブレーションを無効にしようとしています。
NotificationCompat.Builder
次のように、通知を作成するために使用しています。
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(Application.getContext())
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(Notification.PRIORITY_MAX)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(largeIconBitmap)
.setAutoCancel(true)
.setContentIntent(resultPendingIntent)
.setContentTitle(title)
.setContentText(content);
通知を無効にするさまざまな方法を試しました:
notificationBuilder.setVibrate(null);
notificationBuilder.setVibrate(new long[]{0l, 0l});
notificationBuilder.setDefaults(Notification.DEFAULT_ALL | ~Notification.DEFAULT_VIBRATE);
notificationBuilder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND);`
また、通知を作成して、結果のオブジェクトの値を変更しようとしました。
Notification notification = notificationBuilder.build();
notification.vibrate = null;
ただし、通知が表示されると、電話はまだ振動します。
通知のバイブレーションを無効にするにはどうすればよいですか?