Вибрировать не работает с уведомлением
Я пытаюсь установить вибрацию и звук для уведомления. По какой-то причине это не работает для меня : (вот код, который я пытаюсь
NotificationManager notificationManager = getNotificationManager();
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
builder.setSound(alarmSound);
builder.setVibrate(new long[] { 1000, 1000, 1000 });
Notification notification = builder.setContentIntent(contentIntent)
.setSmallIcon(icon).setTicker(title).setWhen(0)
.setAutoCancel(true).setContentTitle(title).setPriority(Notification.PRIORITY_HIGH)
.setStyle(new NotificationCompat.BigTextStyle().bigText(msgToDisply))
.setContentText(msgToDisply).build();
notificationManager.notify(NOTIFICATION, notification);
stopSelf();
И
public NotificationManager getNotificationManager() {
return (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
И у меня есть разрешение в моем манифесте
<uses-permission android:name="android.permission.VIBRATE" />
Есть какие-нибудь догадки, что происходит ?2 ответа:
Это потому, что вы не объявили класс вибратора вибрировать на Notification.In ваш конструктор уведомлений поместите этот код и установите продолжительность вибрации на основе вашего выбора.
Vibrator v = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 500 milliseconds v.vibrate(500);