Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple status bar notifications created in a row produce only one sound alert
    primarykey
    data
    text
    <p>I'm writing a program that monitors several different events and creates status bar notifications when certain conditions are met. The idea is that based on the specific condition there are different notification sounds played, so that the user would know what is happening without having to look at the phone. All notifications are created with different id's (right now random numbers are used, though I may change that later) so they do not override one another. All show up in a status bar and play their notification sounds appropriately.</p> <p>So far so good, but here is a problem. The program main loop in a service sleeps for set amount of time, then wakes up and checks all conditions, creating necessary notifications. It often boils out to having to create two or more notifications in a row. Here comes the problem, only the sound alert of the last notification that is popped up is being played. So the user will never know there was more than one notification about different events just from the sound. </p> <p>Any way this can be remedied? Thanks in advance!</p> <p>UPDATE: After reading some comments and messing around a bit more, it looks like I know WHY this is happening, but not HOW TO FIX it. So the question is still open as of this update. When two notifications popped up as the phone pretty busy (read slow to respond), I could hear the beginning of first sound that was then taken over by the second one. So it looks like the system is honestly trying to play the first sound, but when second notification comes up it simply puts the new sound up cancelling the first playback... So I guess I need to try and find out if there's a way to tell the system to play them in sequence, not all at once...</p> <p>UPDATE2: For now - added code to make sure there is at least 5 seconds between any two notifications being created, and it does solve the problem. As I mentioned in comments below, I don't think it's the best solution, so while this allows me to continue working on the project, I'm still looking for a better way to do it.</p> <p>Here's the code that creates a notification:</p> <pre><code> public void ShowNotification(String Ticker, String Title, String Text,Hero H, Uri Sound, int Icon){ String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); CharSequence tickerText = Ticker; long when = System.currentTimeMillis(); Notification notification = new Notification(Icon, tickerText, when); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.sound=Sound; Context context = getApplicationContext(); CharSequence contentTitle = Title; CharSequence contentText = Text; Intent notificationIntent = new Intent(this, AlertActivity.class); notificationIntent.putExtra(getString(R.string.FROM_NOTIFICATION), true); PendingIntent contentIntent = PendingIntent.getActivity(this, rnd.nextInt(), notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); try{ mNotificationManager.notify(rnd.nextInt(), notification); } catch(Exception e) { Log.w("Service", "Notification Exception: " + e.toString()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload