@imatis/react-native-notifications 4.1.2-imatis.12 → 4.1.2-imatis.16
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,7 +67,7 @@ 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
|
|
@@ -184,7 +186,8 @@ public class PushNotification implements IPushNotification {
|
|
|
184
186
|
.setContentIntent(intent)
|
|
185
187
|
.setDefaults(Notification.DEFAULT_VIBRATE)
|
|
186
188
|
.setAutoCancel(true)
|
|
187
|
-
.setPriority(Notification.PRIORITY_HIGH)
|
|
189
|
+
.setPriority(Notification.PRIORITY_HIGH)
|
|
190
|
+
.setOngoing(mNotificationProps.getOngoing());
|
|
188
191
|
|
|
189
192
|
if (soundUri != null) {
|
|
190
193
|
notification.setSound(soundUri);
|
|
@@ -195,14 +198,10 @@ public class PushNotification implements IPushNotification {
|
|
|
195
198
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
196
199
|
final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
197
200
|
String channelId = mNotificationProps.getChannelId();
|
|
198
|
-
channelId = channelId != null ? channelId : DEFAULT_CHANNEL_ID;
|
|
201
|
+
channelId = channelId != null ? channelId : DEFAULT_CHANNEL_ID + sound;
|
|
199
202
|
NotificationChannel channel = notificationManager.getNotificationChannel(channelId);
|
|
200
|
-
if (channel
|
|
201
|
-
|
|
202
|
-
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
|
|
203
|
-
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
|
|
204
|
-
.build();
|
|
205
|
-
channel.setSound(soundUri, audioAttributes);
|
|
203
|
+
if (channel == null && soundUri != null) {
|
|
204
|
+
initDefaultChannel(mContext, channelId, soundUri);
|
|
206
205
|
}
|
|
207
206
|
notification.setChannelId(channelId);
|
|
208
207
|
}
|
|
@@ -215,6 +214,24 @@ public class PushNotification implements IPushNotification {
|
|
|
215
214
|
Log.d(LOGTAG, e.getMessage());
|
|
216
215
|
}
|
|
217
216
|
|
|
217
|
+
if(mNotificationProps.getCriticalAlert()){
|
|
218
|
+
try {
|
|
219
|
+
MediaPlayer mMediaPlayer = new MediaPlayer();
|
|
220
|
+
mMediaPlayer.setDataSource(mContext.getApplicationContext(), soundUri);
|
|
221
|
+
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
|
|
222
|
+
|
|
223
|
+
mMediaPlayer.prepare();
|
|
224
|
+
mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
|
225
|
+
public void onPrepared(MediaPlayer arg0) {
|
|
226
|
+
mMediaPlayer.seekTo(0);
|
|
227
|
+
mMediaPlayer.start();
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
} catch (Exception e) {
|
|
231
|
+
Log.d(LOGTAG, e.getMessage());
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
218
235
|
return notification;
|
|
219
236
|
}
|
|
220
237
|
|
|
@@ -281,9 +298,9 @@ public class PushNotification implements IPushNotification {
|
|
|
281
298
|
notificationManager.cancelAll();
|
|
282
299
|
}
|
|
283
300
|
|
|
284
|
-
private void initDefaultChannel(Context context) {
|
|
301
|
+
private void initDefaultChannel(Context context, String channelId, Uri soundUri) {
|
|
285
302
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
286
|
-
NotificationChannel defaultChannel = new NotificationChannel(
|
|
303
|
+
NotificationChannel defaultChannel = new NotificationChannel(channelId,
|
|
287
304
|
DEFAULT_CHANNEL_NAME,
|
|
288
305
|
NotificationManager.IMPORTANCE_HIGH);
|
|
289
306
|
defaultChannel.setDescription(DEFAULT_CHANNEL_NAME);
|
|
@@ -293,6 +310,13 @@ public class PushNotification implements IPushNotification {
|
|
|
293
310
|
defaultChannel.enableVibration(true);
|
|
294
311
|
defaultChannel.setShowBadge(true);
|
|
295
312
|
defaultChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
|
|
313
|
+
if (soundUri != null) {
|
|
314
|
+
AudioAttributes audioAttributes = new AudioAttributes.Builder()
|
|
315
|
+
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
|
|
316
|
+
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
|
|
317
|
+
.build();
|
|
318
|
+
defaultChannel.setSound(soundUri, audioAttributes);
|
|
319
|
+
}
|
|
296
320
|
final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
297
321
|
notificationManager.createNotificationChannel(defaultChannel);
|
|
298
322
|
}
|
|
@@ -38,6 +38,26 @@ public class PushNotificationProps {
|
|
|
38
38
|
return mBundle.containsKey("google.message_id");
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
public Boolean getCriticalAlert() {
|
|
42
|
+
String val = mBundle.getString("criticalalert");
|
|
43
|
+
if(val != null && !val.isEmpty()){
|
|
44
|
+
return val.toLowerCase().equals("true");
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public Double getCriticalAlertVolume() {
|
|
50
|
+
String val = mBundle.getString("criticalalertvolume");
|
|
51
|
+
if(val != null && !val.isEmpty()){
|
|
52
|
+
return Double.parseDouble(val);
|
|
53
|
+
}
|
|
54
|
+
return 0.0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public Boolean getOngoing() {
|
|
58
|
+
return mBundle.getBoolean("ongoing");
|
|
59
|
+
}
|
|
60
|
+
|
|
41
61
|
@Override
|
|
42
62
|
public String toString() {
|
|
43
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.
|
|
3
|
+
"version": "4.1.2-imatis.16",
|
|
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",
|