@imatis/react-native-notifications 4.1.2-imatis.13 → 4.1.2-imatis.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,8 @@ import android.content.Context;
9
9
  import android.content.Intent;
10
10
  import android.graphics.Color;
11
11
  import android.media.AudioAttributes;
12
+ import android.media.AudioManager;
13
+ import android.media.MediaPlayer;
12
14
  import android.net.Uri;
13
15
  import android.os.Build;
14
16
  import android.os.Bundle;
@@ -65,15 +67,18 @@ public class PushNotification implements IPushNotification {
65
67
  mAppLaunchHelper = appLaunchHelper;
66
68
  mJsIOHelper = JsIOHelper;
67
69
  mNotificationProps = createProps(bundle);
68
- initDefaultChannel(context);
70
+ // initDefaultChannel(context);
69
71
  }
70
72
 
71
73
  @Override
72
- public void onReceived() throws InvalidNotificationException {
73
- if (!mAppLifecycleFacade.isAppVisible()) {
74
- notifyReceivedBackgroundToJS();
74
+ public void onReceived() {
75
+ ReactContext reactContext = mAppLifecycleFacade.getRunningReactContext();
76
+ boolean hasActiveCatalystInstance = reactContext != null && reactContext.hasActiveCatalystInstance();
77
+ if (!mAppLifecycleFacade.isAppVisible() || !hasActiveCatalystInstance) {
75
78
  postNotification(null);
76
- } else {
79
+ notifyReceivedBackgroundToJS();
80
+ }
81
+ if (hasActiveCatalystInstance) {
77
82
  notifyReceivedToJS();
78
83
  }
79
84
  }
@@ -184,7 +189,8 @@ public class PushNotification implements IPushNotification {
184
189
  .setContentIntent(intent)
185
190
  .setDefaults(Notification.DEFAULT_VIBRATE)
186
191
  .setAutoCancel(true)
187
- .setPriority(Notification.PRIORITY_HIGH);
192
+ .setPriority(Notification.PRIORITY_HIGH)
193
+ .setOngoing(mNotificationProps.getOngoing());
188
194
 
189
195
  if (soundUri != null) {
190
196
  notification.setSound(soundUri);
@@ -195,14 +201,10 @@ public class PushNotification implements IPushNotification {
195
201
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
196
202
  final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
197
203
  String channelId = mNotificationProps.getChannelId();
198
- channelId = channelId != null ? channelId : DEFAULT_CHANNEL_ID;
204
+ channelId = channelId != null ? channelId : DEFAULT_CHANNEL_ID + sound;
199
205
  NotificationChannel channel = notificationManager.getNotificationChannel(channelId);
200
- if (channel != null && soundUri != null) {
201
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
202
- .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
203
- .setUsage(AudioAttributes.USAGE_NOTIFICATION)
204
- .build();
205
- channel.setSound(soundUri, audioAttributes);
206
+ if (channel == null && soundUri != null) {
207
+ initDefaultChannel(mContext, channelId, soundUri);
206
208
  }
207
209
  notification.setChannelId(channelId);
208
210
  }
@@ -299,9 +301,9 @@ public class PushNotification implements IPushNotification {
299
301
  notificationManager.cancelAll();
300
302
  }
301
303
 
302
- private void initDefaultChannel(Context context) {
304
+ private void initDefaultChannel(Context context, String channelId, Uri soundUri) {
303
305
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
304
- NotificationChannel defaultChannel = new NotificationChannel(DEFAULT_CHANNEL_ID,
306
+ NotificationChannel defaultChannel = new NotificationChannel(channelId,
305
307
  DEFAULT_CHANNEL_NAME,
306
308
  NotificationManager.IMPORTANCE_HIGH);
307
309
  defaultChannel.setDescription(DEFAULT_CHANNEL_NAME);
@@ -311,6 +313,13 @@ public class PushNotification implements IPushNotification {
311
313
  defaultChannel.enableVibration(true);
312
314
  defaultChannel.setShowBadge(true);
313
315
  defaultChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
316
+ if (soundUri != null) {
317
+ AudioAttributes audioAttributes = new AudioAttributes.Builder()
318
+ .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
319
+ .setUsage(AudioAttributes.USAGE_NOTIFICATION)
320
+ .build();
321
+ defaultChannel.setSound(soundUri, audioAttributes);
322
+ }
314
323
  final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
315
324
  notificationManager.createNotificationChannel(defaultChannel);
316
325
  }
@@ -54,6 +54,10 @@ public class PushNotificationProps {
54
54
  return 0.0;
55
55
  }
56
56
 
57
+ public Boolean getOngoing() {
58
+ return mBundle.getBoolean("ongoing");
59
+ }
60
+
57
61
  @Override
58
62
  public String toString() {
59
63
  StringBuilder sb = new StringBuilder(1024);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imatis/react-native-notifications",
3
- "version": "4.1.2-imatis.13",
3
+ "version": "4.1.2-imatis.17",
4
4
  "description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android",
5
5
  "author": "Lidan Hifi <lidan.hifi@gmail.com>",
6
6
  "license": "MIT",