2015-10-24 3 views
1

Следующее - это код моего уведомления generationg, но звук продолжает повторяться до тех пор, пока не вытащит строку состояния, чтобы проверить его. Есть идеи?Уведомление Android продолжает повторяться звуковой сигнал уведомления

NotificationManager mNotificationManager; 
     android.support.v7.app.NotificationCompat.Builder mBuilder; 
     Notification mNotification; 
     final int NOTIFICATION_ID = 1; 

     mNotificationManager = (NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE); 

     PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, new Intent(ctx, HomeScreenTabbed.class), 0); 

     Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 

     mBuilder = new android.support.v7.app.NotificationCompat.Builder(ctx); 
     mBuilder.setContentTitle(notificationTitle); 
     mBuilder.setStyle(new android.support.v4.app.NotificationCompat.BigTextStyle().bigText(notificationBody)); 
     mBuilder.setContentText(notificationBody); 
     mBuilder.setContentIntent(contentIntent); 
     mBuilder.setSound(alarmSound); 
     mBuilder.setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_launcher)); 
     mBuilder.setSmallIcon(R.drawable.ic_pollen_notification); 
     mBuilder.setAutoCancel(true); 
     mNotification = mBuilder.build(); 
     // set dismiss on click flags 
     mNotification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_SOUND; 
     mNotificationManager.notify(NOTIFICATION_ID, mNotification); 
+0

Возможный дубликат [Как сделать воспроизведение пользовательских уведомлений звук только один раз] (http://stackoverflow.com/questions/25801365/how-to-make -play-custom-notification-sound-only-once) – user2450263

ответ

6

Я решил проблему с помощью mNotification.defaults вместо mNotification.flags

+1

вы просто не смогли удалить мое приложение. – mjosh

1

Попробуйте добавить флаг FLAG_ONLY_ALERT_ONCE в свое определение mNotification.flags.

http://developer.android.com/reference/android/app/Notification.html#FLAG_ONLY_ALERT_ONCE

Это должно предотвратить отправку звука более чем один раз.

+0

Это отключает звук для всех последующих уведомлений. Кроме того, мне нужно удалить все остальные флаги, чтобы сделать FLAG_ONLY_ALERT_ONCE. –

Смежные вопросы