Skip to content

Commit

Permalink
android, notif: Fix custom sound is not played API >= 26.
Browse files Browse the repository at this point in the history
From API >= 26, Android added support of Notification channels. So now
notifications sounds are handelled by channels, not by notification
itself. So set sound to our one and only defualt channel.

Fixes: zulip#3150
  • Loading branch information
jainkuniya committed Dec 22, 2018
1 parent ab7c436 commit 70583c1
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public static void createNotificationChannel(Context context) {
CharSequence name = context.getString(R.string.notification_channel_name);
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
AudioAttributes audioAttr = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION).build();
channel.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +"://" + context.getPackageName() + NOTIFICATION_SOUND_PATH), audioAttr);
getNotificationManager(context).createNotificationChannel(channel);
}
}
Expand Down Expand Up @@ -173,6 +176,7 @@ private static Notification.Builder getNotificationBuilder(
builder.addAction(action);
}

// Note: This code only set custom sound for API < 26 (from higher API sound is managed by channels)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
AudioAttributes audioAttr = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION).build();
Expand Down

0 comments on commit 70583c1

Please sign in to comment.