There is an application where notification appears when special messages arrive. I try to play my audio file when a notification appears, but nothing happens. At the time of the arrival of specials. messages, the standard sound of the arrival of SMS messages is triggered. There is a suspicion that the notification is launched in the main stream, so my soundtrack does not start, although it is longer than the standard SMS notification. Here is the code:
Intent notificationIntent = new Intent(context, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Resources res = context.getResources(); Notification.Builder builder = new Notification.Builder(context); builder.setContentIntent(contentIntent) .setSmallIcon(R.drawable.notify_icon) .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.notify_icon)) .setTicker("Получено сообщение от информатора!") .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setSound(ringURI) .setContentTitle("Сообщение") .setContentText("Получено новое сообщение от информатора"); Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFY_ID, notification); The path to the file:
Uri ringURI = Uri.parse("android.resource://com.mytest.app/raw/dewdrops2"); UPDATE: I brought the notification in a separate stream, when I received an SMS, my audio recording played for about half a second (and its length was about 10 seconds), but then the standard notification started playing (about 1 second long) and my audio recording stopped playing. What could be the problem and how to solve it?