Skip to content

Commit

Permalink
Fix sounds volume and DND is ignored.
Browse files Browse the repository at this point in the history
Fix #1455 `onNotification fires every time when the app goes from background to foreground`
  • Loading branch information
Dallas62 committed May 25, 2020
1 parent 23e0cb4 commit 9f69896
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public RNPushNotification(ReactApplicationContext reactContext) {
reactContext.addActivityEventListener(this);

Application applicationContext = (Application) reactContext.getApplicationContext();
applicationContext.registerActivityLifecycleCallbacks(this);

// The @ReactNative methods use this
mRNPushNotificationHelper = new RNPushNotificationHelper(applicationContext);
Expand Down Expand Up @@ -280,45 +279,4 @@ public void run() {
}
}).start();
}

@Override
public void onActivityCreated(Activity activity, Bundle bundle) {

}

@Override
public void onActivityStarted(Activity activity) {
Intent intent = activity.getIntent();
Bundle bundle = this.getBundleFromIntent(intent);
if (bundle != null) {
bundle.putBoolean("foreground", false);
intent.putExtra("notification", bundle);
mJsDelivery.notifyNotification(bundle);
}
}

@Override
public void onActivityResumed(Activity activity) {

}

@Override
public void onActivityPaused(Activity activity) {

}

@Override
public void onActivityStopped(Activity activity) {

}

@Override
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {

}

@Override
public void onActivityDestroyed(Activity activity) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ private void checkOrCreateChannel(NotificationManager manager, String channel_id
if (soundUri != null) {
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ALARM)
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build();

channel.setSound(soundUri, audioAttributes);
Expand Down
15 changes: 9 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var Notifications = {
onNotification: false,
onRemoteFetch: false,
isLoaded: false,
hasPoppedInitialNotification: false,
idInitialNotification: null,

isPermissionsRequestPending: false,

Expand Down Expand Up @@ -84,14 +84,17 @@ Notifications.configure = function(options) {
this.isLoaded = true;
}

if ( this.hasPoppedInitialNotification === false &&
( options.popInitialNotification === undefined || options.popInitialNotification === true ) ) {
if (options.popInitialNotification === undefined || options.popInitialNotification === true) {
this.popInitialNotification(function(firstNotification) {
if ( firstNotification !== null ) {
this._onNotification(firstNotification, true);
if(this.idInitialNotification === firstNotification.id) {
return;
}

this.idInitialNotification = firstNotification.id;
this._onNotification(firstNotification, true);
}
}.bind(this));
this.hasPoppedInitialNotification = true;
}.bind(this));
}

if ( options.requestPermissions !== false ) {
Expand Down

0 comments on commit 9f69896

Please sign in to comment.