Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 9f69896

Browse files
committed
Fix sounds volume and DND is ignored.
Fix #1455 `onNotification fires every time when the app goes from background to foreground`
1 parent 23e0cb4 commit 9f69896

File tree

3 files changed

+10
-49
lines changed

3 files changed

+10
-49
lines changed

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public RNPushNotification(ReactApplicationContext reactContext) {
5151
reactContext.addActivityEventListener(this);
5252

5353
Application applicationContext = (Application) reactContext.getApplicationContext();
54-
applicationContext.registerActivityLifecycleCallbacks(this);
5554

5655
// The @ReactNative methods use this
5756
mRNPushNotificationHelper = new RNPushNotificationHelper(applicationContext);
@@ -280,45 +279,4 @@ public void run() {
280279
}
281280
}).start();
282281
}
283-
284-
@Override
285-
public void onActivityCreated(Activity activity, Bundle bundle) {
286-
287-
}
288-
289-
@Override
290-
public void onActivityStarted(Activity activity) {
291-
Intent intent = activity.getIntent();
292-
Bundle bundle = this.getBundleFromIntent(intent);
293-
if (bundle != null) {
294-
bundle.putBoolean("foreground", false);
295-
intent.putExtra("notification", bundle);
296-
mJsDelivery.notifyNotification(bundle);
297-
}
298-
}
299-
300-
@Override
301-
public void onActivityResumed(Activity activity) {
302-
303-
}
304-
305-
@Override
306-
public void onActivityPaused(Activity activity) {
307-
308-
}
309-
310-
@Override
311-
public void onActivityStopped(Activity activity) {
312-
313-
}
314-
315-
@Override
316-
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
317-
318-
}
319-
320-
@Override
321-
public void onActivityDestroyed(Activity activity) {
322-
323-
}
324282
}

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ private void checkOrCreateChannel(NotificationManager manager, String channel_id
719719
if (soundUri != null) {
720720
AudioAttributes audioAttributes = new AudioAttributes.Builder()
721721
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
722-
.setUsage(AudioAttributes.USAGE_ALARM)
722+
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
723723
.build();
724724

725725
channel.setSound(soundUri, audioAttributes);

index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var Notifications = {
1818
onNotification: false,
1919
onRemoteFetch: false,
2020
isLoaded: false,
21-
hasPoppedInitialNotification: false,
21+
idInitialNotification: null,
2222

2323
isPermissionsRequestPending: false,
2424

@@ -84,14 +84,17 @@ Notifications.configure = function(options) {
8484
this.isLoaded = true;
8585
}
8686

87-
if ( this.hasPoppedInitialNotification === false &&
88-
( options.popInitialNotification === undefined || options.popInitialNotification === true ) ) {
87+
if (options.popInitialNotification === undefined || options.popInitialNotification === true) {
8988
this.popInitialNotification(function(firstNotification) {
9089
if ( firstNotification !== null ) {
91-
this._onNotification(firstNotification, true);
90+
if(this.idInitialNotification === firstNotification.id) {
91+
return;
92+
}
93+
94+
this.idInitialNotification = firstNotification.id;
95+
this._onNotification(firstNotification, true);
9296
}
93-
}.bind(this));
94-
this.hasPoppedInitialNotification = true;
97+
}.bind(this));
9598
}
9699

97100
if ( options.requestPermissions !== false ) {

0 commit comments

Comments
 (0)