Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26432] Android: Custom sounds are not played for local notifications on Android 8.0+

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionInvalid
Resolution Date2018-10-25T01:52:15.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterLokesh Choudhary
AssigneeJoshua Quick
Created2018-10-02T22:29:32.000+0000
Updated2018-10-26T08:26:58.000+0000

Description

Steps to reproduce:

1. Use the code below in your app.js:
var channel = Ti.Android.NotificationManager.createNotificationChannel({
        id: 'my_channel',
        name: 'TEST CHANNEL',
        importance: Ti.Android.IMPORTANCE_DEFAULT
   }),
   notification = Titanium.Android.createNotification({
    		contentTitle: 'Notification 2',
	    contentText : 'Just another notification',
	    contentIntent: Ti.Android.createPendingIntent({intent: Ti.Android.createIntent({})}),
	    icon: Ti.App.Android.R.drawable.warn,
	    number: 5,
	    when: new Date().getTime(),
	    // Sound file located at /platform/android/res/raw/test.wav
		sound: Ti.Filesystem.getResRawDirectory() + 'test.wav',
	});

setInterval(function(){
	Ti.Android.NotificationManager.notify(100, notification);
}, 5000);
2. Build for android device/emulator. 3. After the app launch you will get a local notification with custom sound every 5 seconds.

Actual results:

1. On Android 7.0 & older the custom sound works fine. 2. On Android 8.0+ the custom sound does not play but the default system notification sound plays.

Expected results:

1. Custom sounds should play consistently on all Android versions.

Comments

  1. Joshua Quick 2018-10-23

    This looks like an undocumented breaking-change on Google's end. I believe you're supposed to assign the custom sound to the notification channel now via the Java NotificaitonChannel.setSound() method and the sound assigned to individual notifications are now ignored. [NotificationChannel.setSound()](https://developer.android.com/reference/android/app/NotificationChannel.html#setSound(android.net.Uri,%20android.media.AudioAttributes)) The problem with assigning the sound to the notification channel is that you can't change the sound file unless you delete and recreate the channel. Hmm...
  2. Joshua Quick 2018-10-23

    Yeah, the Java Notification.Builder.setSound() method is definitely deprecated as can be seen here... [Notification.Builder.setSound()](https://developer.android.com/reference/android/app/Notification.Builder.html#setSound(android.net.Uri)) Unfortunately, it wasn't documented as deprecated on the Google support library side that we were using here... [NotificationCompat.Builder.setSound()](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setsound)
  3. Joshua Quick 2018-10-25

    Unfortunately, this issue cannot be *+fixed+*. The solution is to provide a new feature where you can assign a "sound" to NotificationChannel. This will be implemented via: [TIMOB-26484]

JSON Source