Skip to content

Commit

Permalink
[notifications] allow sound to play when shouldShowAlert is false (ex…
Browse files Browse the repository at this point in the history
…po#10699)

* [notifications] allow sound to play when shouldShowAlert is false

* changelog

* changelog part 2
  • Loading branch information
cruzach authored Oct 16, 2020
1 parent 1eda1af commit 3cd0e7d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/expo-notifications/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Fixed fatal exception sometimes being thrown when notification was received or tapped on Android due to observer being cleared before it's added. ([#10640](https://github.com/expo/expo/pull/10640) by [@sjchmiela](https://github.com/sjchmiela))
- Removed the large icon from managed workflow. ([#10492](https://github.com/expo/expo/pull/10492) by [@lukmccall](https://github.com/lukmccall))
- Fixed crash happening due to non-existent `ExpoNotificationsService` being declared in `AndroidManifest.xml`. ([#10638](https://github.com/expo/expo/pull/10638) by [@sjchmiela](https://github.com/sjchmiela))
- Fixed notifications _not_ playing any sound when `shouldShowAlert: false` but `shouldPlaySound: true` in `setNotificationHandler`. ([#10699](https://github.com/expo/expo/pull/10699) by [@cruzach](https://github.com/cruzach))

## 0.7.1 — 2020-08-26

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@
*/
/* package */ void handleResponse(NotificationBehavior behavior, final Promise promise) {
mBehavior = behavior;
if (!behavior.shouldShowAlert()) {
promise.resolve(null);
finish();
return;
}

mHandler.post(new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package expo.modules.notifications.service.delegates

import android.app.NotificationManager
import android.content.Context
import android.media.RingtoneManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Parcel
import android.provider.Settings
import android.service.notification.StatusBarNotification
import android.util.Log
import android.util.Pair
Expand Down Expand Up @@ -81,7 +83,23 @@ open class ExpoPresentationDelegate(
}
}

/**
* Callback called to present the system UI for a notification.
*
* If the notification behavior is set to not show any alert,
* we (may) play a sound, but then bail out early. You cannot
* set badge count without showing a notification.
*/
override fun presentNotification(notification: Notification, behavior: NotificationBehavior?) {
if (behavior != null && !behavior.shouldShowAlert()) {
if (behavior.shouldPlaySound()) {
RingtoneManager.getRingtone(
context,
notification.notificationRequest.content.sound ?: Settings.System.DEFAULT_NOTIFICATION_URI
).play()
}
return
}
val tag = notification.notificationRequest.identifier
NotificationManagerCompat.from(context).notify(tag, ANDROID_NOTIFICATION_ID, createNotification(notification, behavior))
}
Expand Down

0 comments on commit 3cd0e7d

Please sign in to comment.