@psync/notifee 9.2.0
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.
- package/LICENSE +44 -0
- package/README.md +142 -0
- package/RNNotifee.podspec +39 -0
- package/RNNotifeeCore.podspec +33 -0
- package/android/.editorconfig +10 -0
- package/android/build.gradle +116 -0
- package/android/gradle.properties +1 -0
- package/android/lint.xml +5 -0
- package/android/proguard-rules.pro +82 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/java/io/invertase/notifee/HeadlessTask.java +431 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeApiModule.java +365 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeEventSubscriber.java +118 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeInitProvider.java +55 -0
- package/android/src/main/java/io/invertase/notifee/NotifeePackage.java +30 -0
- package/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java +135 -0
- package/dist/NotifeeApiModule.d.ts +53 -0
- package/dist/NotifeeApiModule.js +609 -0
- package/dist/NotifeeApiModule.js.map +1 -0
- package/dist/NotifeeJSEventEmitter.d.ts +3 -0
- package/dist/NotifeeJSEventEmitter.js +14 -0
- package/dist/NotifeeJSEventEmitter.js.map +1 -0
- package/dist/NotifeeNativeError.d.ts +15 -0
- package/dist/NotifeeNativeError.js +59 -0
- package/dist/NotifeeNativeError.js.map +1 -0
- package/dist/NotifeeNativeModule.d.ts +14 -0
- package/dist/NotifeeNativeModule.js +42 -0
- package/dist/NotifeeNativeModule.js.map +1 -0
- package/dist/NotifeeNativeModule.web.d.ts +12 -0
- package/dist/NotifeeNativeModule.web.js +18 -0
- package/dist/NotifeeNativeModule.web.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/types/Library.d.ts +21 -0
- package/dist/types/Library.js +6 -0
- package/dist/types/Library.js.map +1 -0
- package/dist/types/Module.d.ts +576 -0
- package/dist/types/Module.js +6 -0
- package/dist/types/Module.js.map +1 -0
- package/dist/types/Notification.d.ts +462 -0
- package/dist/types/Notification.js +111 -0
- package/dist/types/Notification.js.map +1 -0
- package/dist/types/NotificationAndroid.d.ts +1311 -0
- package/dist/types/NotificationAndroid.js +409 -0
- package/dist/types/NotificationAndroid.js.map +1 -0
- package/dist/types/NotificationIOS.d.ts +539 -0
- package/dist/types/NotificationIOS.js +92 -0
- package/dist/types/NotificationIOS.js.map +1 -0
- package/dist/types/NotificationWeb.d.ts +5 -0
- package/dist/types/NotificationWeb.js +6 -0
- package/dist/types/NotificationWeb.js.map +1 -0
- package/dist/types/PowerManagerInfo.d.ts +36 -0
- package/dist/types/PowerManagerInfo.js +6 -0
- package/dist/types/PowerManagerInfo.js.map +1 -0
- package/dist/types/Trigger.d.ts +124 -0
- package/dist/types/Trigger.js +51 -0
- package/dist/types/Trigger.js.map +1 -0
- package/dist/utils/id.d.ts +1 -0
- package/dist/utils/id.js +15 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/index.d.ts +16 -0
- package/dist/utils/index.js +51 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/validate.d.ts +15 -0
- package/dist/utils/validate.js +90 -0
- package/dist/utils/validate.js.map +1 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.d.ts +2 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js +51 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfo.js.map +1 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.d.ts +2 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js +27 -0
- package/dist/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.js.map +1 -0
- package/dist/validators/validate.d.ts +25 -0
- package/dist/validators/validate.js +74 -0
- package/dist/validators/validate.js.map +1 -0
- package/dist/validators/validateAndroidAction.d.ts +2 -0
- package/dist/validators/validateAndroidAction.js +52 -0
- package/dist/validators/validateAndroidAction.js.map +1 -0
- package/dist/validators/validateAndroidChannel.d.ts +2 -0
- package/dist/validators/validateAndroidChannel.js +155 -0
- package/dist/validators/validateAndroidChannel.js.map +1 -0
- package/dist/validators/validateAndroidChannelGroup.d.ts +2 -0
- package/dist/validators/validateAndroidChannelGroup.js +42 -0
- package/dist/validators/validateAndroidChannelGroup.js.map +1 -0
- package/dist/validators/validateAndroidFullScreenAction.d.ts +2 -0
- package/dist/validators/validateAndroidFullScreenAction.js +50 -0
- package/dist/validators/validateAndroidFullScreenAction.js.map +1 -0
- package/dist/validators/validateAndroidInput.d.ts +2 -0
- package/dist/validators/validateAndroidInput.js +54 -0
- package/dist/validators/validateAndroidInput.js.map +1 -0
- package/dist/validators/validateAndroidNotification.d.ts +2 -0
- package/dist/validators/validateAndroidNotification.js +547 -0
- package/dist/validators/validateAndroidNotification.js.map +1 -0
- package/dist/validators/validateAndroidPressAction.d.ts +2 -0
- package/dist/validators/validateAndroidPressAction.js +50 -0
- package/dist/validators/validateAndroidPressAction.js.map +1 -0
- package/dist/validators/validateAndroidStyle.d.ts +22 -0
- package/dist/validators/validateAndroidStyle.js +230 -0
- package/dist/validators/validateAndroidStyle.js.map +1 -0
- package/dist/validators/validateIOSAttachment.d.ts +6 -0
- package/dist/validators/validateIOSAttachment.js +100 -0
- package/dist/validators/validateIOSAttachment.js.map +1 -0
- package/dist/validators/validateIOSCategory.d.ts +2 -0
- package/dist/validators/validateIOSCategory.js +124 -0
- package/dist/validators/validateIOSCategory.js.map +1 -0
- package/dist/validators/validateIOSCategoryAction.d.ts +2 -0
- package/dist/validators/validateIOSCategoryAction.js +59 -0
- package/dist/validators/validateIOSCategoryAction.js.map +1 -0
- package/dist/validators/validateIOSInput.d.ts +2 -0
- package/dist/validators/validateIOSInput.js +32 -0
- package/dist/validators/validateIOSInput.js.map +1 -0
- package/dist/validators/validateIOSNotification.d.ts +2 -0
- package/dist/validators/validateIOSNotification.js +211 -0
- package/dist/validators/validateIOSNotification.js.map +1 -0
- package/dist/validators/validateIOSPermissions.d.ts +2 -0
- package/dist/validators/validateIOSPermissions.js +62 -0
- package/dist/validators/validateIOSPermissions.js.map +1 -0
- package/dist/validators/validateNotification.d.ts +11 -0
- package/dist/validators/validateNotification.js +129 -0
- package/dist/validators/validateNotification.js.map +1 -0
- package/dist/validators/validateTrigger.d.ts +2 -0
- package/dist/validators/validateTrigger.js +110 -0
- package/dist/validators/validateTrigger.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/ios/NotifeeCore/Info.plist +22 -0
- package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.h +28 -0
- package/ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m +76 -0
- package/ios/NotifeeCore/NotifeeCore+NSURLSession.h +25 -0
- package/ios/NotifeeCore/NotifeeCore+NSURLSession.m +55 -0
- package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.h +44 -0
- package/ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m +270 -0
- package/ios/NotifeeCore/NotifeeCore.h +118 -0
- package/ios/NotifeeCore/NotifeeCore.m +843 -0
- package/ios/NotifeeCore/NotifeeCoreDelegateHolder.h +34 -0
- package/ios/NotifeeCore/NotifeeCoreDelegateHolder.m +70 -0
- package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.h +39 -0
- package/ios/NotifeeCore/NotifeeCoreDownloadDelegate.m +68 -0
- package/ios/NotifeeCore/NotifeeCoreExtensionHelper.h +38 -0
- package/ios/NotifeeCore/NotifeeCoreExtensionHelper.m +224 -0
- package/ios/NotifeeCore/NotifeeCoreUtil.h +81 -0
- package/ios/NotifeeCore/NotifeeCoreUtil.m +834 -0
- package/ios/RNNotifee/NotifeeApiModule.h +25 -0
- package/ios/RNNotifee/NotifeeApiModule.m +371 -0
- package/ios/RNNotifee/NotifeeExtensionHelper.h +37 -0
- package/ios/RNNotifee/NotifeeExtensionHelper.m +37 -0
- package/ios/RNNotifee.xcodeproj/project.pbxproj +318 -0
- package/ios/RNNotifee.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/RNNotifee.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/jest-mock.js +161 -0
- package/package.json +74 -0
- package/react-native.config.js +11 -0
- package/src/NotifeeApiModule.ts +827 -0
- package/src/NotifeeJSEventEmitter.ts +10 -0
- package/src/NotifeeNativeError.ts +68 -0
- package/src/NotifeeNativeModule.ts +54 -0
- package/src/NotifeeNativeModule.web.ts +24 -0
- package/src/index.ts +33 -0
- package/src/types/Library.ts +28 -0
- package/src/types/Module.ts +629 -0
- package/src/types/Notification.ts +518 -0
- package/src/types/NotificationAndroid.ts +1478 -0
- package/src/types/NotificationIOS.ts +683 -0
- package/src/types/NotificationWeb.ts +5 -0
- package/src/types/PowerManagerInfo.ts +43 -0
- package/src/types/Trigger.ts +136 -0
- package/src/utils/id.ts +13 -0
- package/src/utils/index.ts +46 -0
- package/src/utils/validate.ts +90 -0
- package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfo.ts +61 -0
- package/src/validators/iosCommunicationInfo/validateIOSCommunicationInfoPerson.ts +33 -0
- package/src/validators/validate.ts +85 -0
- package/src/validators/validateAndroidAction.ts +54 -0
- package/src/validators/validateAndroidChannel.ts +188 -0
- package/src/validators/validateAndroidChannelGroup.ts +49 -0
- package/src/validators/validateAndroidFullScreenAction.ts +65 -0
- package/src/validators/validateAndroidInput.ts +67 -0
- package/src/validators/validateAndroidNotification.ts +734 -0
- package/src/validators/validateAndroidPressAction.ts +65 -0
- package/src/validators/validateAndroidStyle.ts +315 -0
- package/src/validators/validateIOSAttachment.ts +135 -0
- package/src/validators/validateIOSCategory.ts +150 -0
- package/src/validators/validateIOSCategoryAction.ts +65 -0
- package/src/validators/validateIOSInput.ts +38 -0
- package/src/validators/validateIOSNotification.ts +296 -0
- package/src/validators/validateIOSPermissions.ts +78 -0
- package/src/validators/validateNotification.ts +156 -0
- package/src/validators/validateTrigger.ts +142 -0
- package/src/version.ts +2 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
package io.invertase.notifee;
|
|
6
|
+
|
|
7
|
+
import android.Manifest;
|
|
8
|
+
import android.os.Build;
|
|
9
|
+
import android.os.Bundle;
|
|
10
|
+
import androidx.annotation.NonNull;
|
|
11
|
+
import app.notifee.core.Logger;
|
|
12
|
+
import app.notifee.core.Notifee;
|
|
13
|
+
import com.facebook.react.bridge.Arguments;
|
|
14
|
+
import com.facebook.react.bridge.Promise;
|
|
15
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
16
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
17
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
18
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
19
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
20
|
+
import com.facebook.react.modules.core.PermissionAwareActivity;
|
|
21
|
+
import com.facebook.react.modules.core.PermissionListener;
|
|
22
|
+
import java.util.ArrayList;
|
|
23
|
+
import java.util.HashMap;
|
|
24
|
+
import java.util.Map;
|
|
25
|
+
|
|
26
|
+
public class NotifeeApiModule extends ReactContextBaseJavaModule implements PermissionListener {
|
|
27
|
+
private static final int NOTIFICATION_TYPE_DISPLAYED = 1;
|
|
28
|
+
private static final int NOTIFICATION_TYPE_TRIGGER = 2;
|
|
29
|
+
private static final int NOTIFICATION_TYPE_ALL = 0;
|
|
30
|
+
|
|
31
|
+
public NotifeeApiModule(@NonNull ReactApplicationContext reactContext) {
|
|
32
|
+
super(reactContext);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public static String getMainComponent(@NonNull String defaultComponent) {
|
|
36
|
+
return Notifee.getInstance().getMainComponent(defaultComponent);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// This method was removed upstream in react-native 0.74+, replaced with invalidate
|
|
40
|
+
// We will leave this stub here for older react-native versions compatibility
|
|
41
|
+
// ...but it will just delegate to the new invalidate method
|
|
42
|
+
public void onCatalystInstanceDestroy() {
|
|
43
|
+
invalidate();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// This method was added in react-native 0.74 as a replacement for onCatalystInstanceDestroy
|
|
47
|
+
// It should be marked @Override but that would cause problems in apps using older react-native
|
|
48
|
+
// When minimum supported version is 0.74+ add @Override & remove onCatalystInstanceDestroy
|
|
49
|
+
public void invalidate() {
|
|
50
|
+
NotifeeReactUtils.headlessTaskManager.stopAllTasks();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@ReactMethod
|
|
54
|
+
public void cancelAllNotifications(Promise promise) {
|
|
55
|
+
Notifee.getInstance()
|
|
56
|
+
.cancelAllNotifications(
|
|
57
|
+
NOTIFICATION_TYPE_ALL, (e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@ReactMethod
|
|
61
|
+
public void cancelDisplayedNotifications(Promise promise) {
|
|
62
|
+
Notifee.getInstance()
|
|
63
|
+
.cancelAllNotifications(
|
|
64
|
+
NOTIFICATION_TYPE_DISPLAYED,
|
|
65
|
+
(e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@ReactMethod
|
|
69
|
+
public void cancelTriggerNotifications(Promise promise) {
|
|
70
|
+
Notifee.getInstance()
|
|
71
|
+
.cancelAllNotifications(
|
|
72
|
+
NOTIFICATION_TYPE_TRIGGER, (e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@ReactMethod
|
|
76
|
+
public void cancelAllNotificationsWithIds(
|
|
77
|
+
ReadableArray idsArray, int notificationType, String tag, Promise promise) {
|
|
78
|
+
ArrayList<String> ids = new ArrayList<>(idsArray.size());
|
|
79
|
+
for (int i = 0; i < idsArray.size(); i++) {
|
|
80
|
+
ids.add(idsArray.getString(i));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
Notifee.getInstance()
|
|
84
|
+
.cancelAllNotificationsWithIds(
|
|
85
|
+
notificationType,
|
|
86
|
+
ids,
|
|
87
|
+
tag,
|
|
88
|
+
(e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@ReactMethod
|
|
92
|
+
public void getDisplayedNotifications(Promise promise) {
|
|
93
|
+
Notifee.getInstance()
|
|
94
|
+
.getDisplayedNotifications(
|
|
95
|
+
(e, aBundleList) -> NotifeeReactUtils.promiseResolver(promise, e, aBundleList));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@ReactMethod
|
|
99
|
+
public void getTriggerNotifications(Promise promise) {
|
|
100
|
+
Notifee.getInstance()
|
|
101
|
+
.getTriggerNotifications(
|
|
102
|
+
(e, aBundleList) -> NotifeeReactUtils.promiseResolver(promise, e, aBundleList));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@ReactMethod
|
|
106
|
+
public void getTriggerNotificationIds(Promise promise) {
|
|
107
|
+
Notifee.getInstance()
|
|
108
|
+
.getTriggerNotificationIds(
|
|
109
|
+
(e, aStringList) ->
|
|
110
|
+
NotifeeReactUtils.promiseStringListResolver(promise, e, aStringList));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@ReactMethod
|
|
114
|
+
public void createChannel(ReadableMap channelMap, Promise promise) {
|
|
115
|
+
Notifee.getInstance()
|
|
116
|
+
.createChannel(
|
|
117
|
+
Arguments.toBundle(channelMap),
|
|
118
|
+
(e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@ReactMethod
|
|
122
|
+
public void createChannels(ReadableArray channelsArray, Promise promise) {
|
|
123
|
+
ArrayList<Bundle> channels = new ArrayList<>(channelsArray.size());
|
|
124
|
+
for (int i = 0; i < channelsArray.size(); i++) {
|
|
125
|
+
channels.add(Arguments.toBundle(channelsArray.getMap(i)));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
Notifee.getInstance()
|
|
129
|
+
.createChannels(channels, (e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@ReactMethod
|
|
133
|
+
public void createChannelGroup(ReadableMap channelGroupMap, Promise promise) {
|
|
134
|
+
Notifee.getInstance()
|
|
135
|
+
.createChannelGroup(
|
|
136
|
+
Arguments.toBundle(channelGroupMap),
|
|
137
|
+
(e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@ReactMethod
|
|
141
|
+
public void createChannelGroups(ReadableArray channelGroupsArray, Promise promise) {
|
|
142
|
+
ArrayList<Bundle> channelGroups = new ArrayList<>(channelGroupsArray.size());
|
|
143
|
+
|
|
144
|
+
for (int i = 0; i < channelGroupsArray.size(); i++) {
|
|
145
|
+
channelGroups.add(Arguments.toBundle(channelGroupsArray.getMap(i)));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
Notifee.getInstance()
|
|
149
|
+
.createChannelGroups(
|
|
150
|
+
channelGroups, (e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@ReactMethod
|
|
154
|
+
public void deleteChannel(String channelId, Promise promise) {
|
|
155
|
+
Notifee.getInstance()
|
|
156
|
+
.deleteChannel(channelId, (e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@ReactMethod
|
|
160
|
+
public void deleteChannelGroup(String channelId, Promise promise) {
|
|
161
|
+
Notifee.getInstance()
|
|
162
|
+
.deleteChannelGroup(channelId, (e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@ReactMethod
|
|
166
|
+
public void displayNotification(ReadableMap notificationMap, Promise promise) {
|
|
167
|
+
Notifee.getInstance()
|
|
168
|
+
.displayNotification(
|
|
169
|
+
Arguments.toBundle(notificationMap),
|
|
170
|
+
(e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@ReactMethod
|
|
174
|
+
public void openAlarmPermissionSettings(Promise promise) {
|
|
175
|
+
Notifee.getInstance()
|
|
176
|
+
.openAlarmPermissionSettings(
|
|
177
|
+
getCurrentActivity(), (e, avoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
@ReactMethod
|
|
181
|
+
public void createTriggerNotification(
|
|
182
|
+
ReadableMap notificationMap, ReadableMap triggerMap, Promise promise) {
|
|
183
|
+
Notifee.getInstance()
|
|
184
|
+
.createTriggerNotification(
|
|
185
|
+
Arguments.toBundle(notificationMap),
|
|
186
|
+
Arguments.toBundle(triggerMap),
|
|
187
|
+
(e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
@ReactMethod
|
|
191
|
+
public void getChannels(Promise promise) {
|
|
192
|
+
Notifee.getInstance()
|
|
193
|
+
.getChannels(
|
|
194
|
+
(e, aBundleList) -> NotifeeReactUtils.promiseResolver(promise, e, aBundleList));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@ReactMethod
|
|
198
|
+
public void getChannel(String channelId, Promise promise) {
|
|
199
|
+
Notifee.getInstance()
|
|
200
|
+
.getChannel(
|
|
201
|
+
channelId, (e, aBundle) -> NotifeeReactUtils.promiseResolver(promise, e, aBundle));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
@ReactMethod
|
|
205
|
+
public void getChannelGroups(Promise promise) {
|
|
206
|
+
Notifee.getInstance()
|
|
207
|
+
.getChannelGroups(
|
|
208
|
+
(e, aBundleList) -> NotifeeReactUtils.promiseResolver(promise, e, aBundleList));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@ReactMethod
|
|
212
|
+
public void getChannelGroup(String channelGroupId, Promise promise) {
|
|
213
|
+
Notifee.getInstance()
|
|
214
|
+
.getChannel(
|
|
215
|
+
channelGroupId, (e, aBundle) -> NotifeeReactUtils.promiseResolver(promise, e, aBundle));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
@ReactMethod
|
|
219
|
+
public void isChannelCreated(String channelId, Promise promise) {
|
|
220
|
+
Notifee.getInstance()
|
|
221
|
+
.isChannelCreated(
|
|
222
|
+
channelId, (e, aBool) -> NotifeeReactUtils.promiseBooleanResolver(promise, e, aBool));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
@ReactMethod
|
|
226
|
+
public void isChannelBlocked(String channelId, Promise promise) {
|
|
227
|
+
Notifee.getInstance()
|
|
228
|
+
.isChannelBlocked(
|
|
229
|
+
channelId, (e, aBool) -> NotifeeReactUtils.promiseBooleanResolver(promise, e, aBool));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
@ReactMethod
|
|
233
|
+
public void getInitialNotification(Promise promise) {
|
|
234
|
+
Notifee.getInstance()
|
|
235
|
+
.getInitialNotification(
|
|
236
|
+
getCurrentActivity(),
|
|
237
|
+
(e, aBundle) -> NotifeeReactUtils.promiseResolver(promise, e, aBundle));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
@ReactMethod
|
|
241
|
+
public void getNotificationSettings(Promise promise) {
|
|
242
|
+
Notifee.getInstance()
|
|
243
|
+
.getNotificationSettings(
|
|
244
|
+
(e, aBundle) -> NotifeeReactUtils.promiseResolver(promise, e, aBundle));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
@ReactMethod
|
|
248
|
+
public void requestPermission(Promise promise) {
|
|
249
|
+
// For Android 12 and below, we return the notification settings
|
|
250
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
|
251
|
+
Notifee.getInstance()
|
|
252
|
+
.getNotificationSettings(
|
|
253
|
+
(e, aBundle) -> NotifeeReactUtils.promiseResolver(promise, e, aBundle));
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// We have to handle this logic outside of our core module due to a react-native limitation
|
|
258
|
+
// with obtaining the correct activity
|
|
259
|
+
PermissionAwareActivity activity = (PermissionAwareActivity) getCurrentActivity();
|
|
260
|
+
if (activity == null) {
|
|
261
|
+
Logger.d(
|
|
262
|
+
"requestPermission",
|
|
263
|
+
"Unable to get permissionAwareActivity for " + Build.VERSION.SDK_INT);
|
|
264
|
+
|
|
265
|
+
Notifee.getInstance()
|
|
266
|
+
.getNotificationSettings(
|
|
267
|
+
(e, aBundle) -> NotifeeReactUtils.promiseResolver(promise, e, aBundle));
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Setting the request permission callback before attempting to call requestPermissions
|
|
272
|
+
Notifee.getInstance()
|
|
273
|
+
.setRequestPermissionCallback(
|
|
274
|
+
(e, aBundle) -> NotifeeReactUtils.promiseResolver(promise, e, aBundle));
|
|
275
|
+
|
|
276
|
+
try {
|
|
277
|
+
activity.requestPermissions(
|
|
278
|
+
new String[] {Manifest.permission.POST_NOTIFICATIONS},
|
|
279
|
+
Notifee.REQUEST_CODE_NOTIFICATION_PERMISSION,
|
|
280
|
+
this);
|
|
281
|
+
} catch (Exception e) {
|
|
282
|
+
Logger.d(
|
|
283
|
+
"requestPermission",
|
|
284
|
+
"Failed to request POST_NOTIFICATIONS permission: " + e.getMessage());
|
|
285
|
+
NotifeeReactUtils.promiseResolver(promise, e);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
@ReactMethod
|
|
290
|
+
public void openNotificationSettings(String channelId, Promise promise) {
|
|
291
|
+
Notifee.getInstance()
|
|
292
|
+
.openNotificationSettings(
|
|
293
|
+
channelId,
|
|
294
|
+
getCurrentActivity(),
|
|
295
|
+
(e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
@ReactMethod
|
|
299
|
+
public void openBatteryOptimizationSettings(Promise promise) {
|
|
300
|
+
Notifee.getInstance()
|
|
301
|
+
.openBatteryOptimizationSettings(
|
|
302
|
+
getCurrentActivity(), (e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
@ReactMethod
|
|
306
|
+
public void isBatteryOptimizationEnabled(Promise promise) {
|
|
307
|
+
Notifee.getInstance()
|
|
308
|
+
.isBatteryOptimizationEnabled(
|
|
309
|
+
(e, aBool) -> NotifeeReactUtils.promiseBooleanResolver(promise, e, aBool));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
@ReactMethod
|
|
313
|
+
public void getPowerManagerInfo(Promise promise) {
|
|
314
|
+
Notifee.getInstance()
|
|
315
|
+
.getPowerManagerInfo(
|
|
316
|
+
(e, aBundle) -> NotifeeReactUtils.promiseResolver(promise, e, aBundle));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
@ReactMethod
|
|
320
|
+
public void openPowerManagerSettings(Promise promise) {
|
|
321
|
+
Notifee.getInstance()
|
|
322
|
+
.openPowerManagerSettings(
|
|
323
|
+
getCurrentActivity(), (e, avoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
@ReactMethod
|
|
327
|
+
public void stopForegroundService(Promise promise) {
|
|
328
|
+
Notifee.getInstance()
|
|
329
|
+
.stopForegroundService((e, aVoid) -> NotifeeReactUtils.promiseResolver(promise, e));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
@ReactMethod
|
|
333
|
+
public void hideNotificationDrawer() {
|
|
334
|
+
NotifeeReactUtils.hideNotificationDrawer();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
@ReactMethod
|
|
338
|
+
public void addListener(String eventName) {
|
|
339
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
@ReactMethod
|
|
343
|
+
public void removeListeners(Integer count) {
|
|
344
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
@NonNull
|
|
348
|
+
@Override
|
|
349
|
+
public String getName() {
|
|
350
|
+
return "NotifeeApiModule";
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
@Override
|
|
354
|
+
public Map<String, Object> getConstants() {
|
|
355
|
+
Map<String, Object> constants = new HashMap<>();
|
|
356
|
+
constants.put("ANDROID_API_LEVEL", android.os.Build.VERSION.SDK_INT);
|
|
357
|
+
return constants;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
@Override
|
|
361
|
+
public boolean onRequestPermissionsResult(
|
|
362
|
+
int requestCode, String[] permissions, int[] grantResults) {
|
|
363
|
+
return Notifee.getInstance().onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
package io.invertase.notifee;
|
|
6
|
+
|
|
7
|
+
import static io.invertase.notifee.NotifeeReactUtils.isAppInForeground;
|
|
8
|
+
|
|
9
|
+
import android.os.Bundle;
|
|
10
|
+
import androidx.annotation.Keep;
|
|
11
|
+
import app.notifee.core.event.BlockStateEvent;
|
|
12
|
+
import app.notifee.core.event.ForegroundServiceEvent;
|
|
13
|
+
import app.notifee.core.event.LogEvent;
|
|
14
|
+
import app.notifee.core.event.NotificationEvent;
|
|
15
|
+
import app.notifee.core.interfaces.EventListener;
|
|
16
|
+
import app.notifee.core.model.NotificationModel;
|
|
17
|
+
import com.facebook.react.bridge.Arguments;
|
|
18
|
+
import com.facebook.react.bridge.WritableMap;
|
|
19
|
+
|
|
20
|
+
@Keep
|
|
21
|
+
public class NotifeeEventSubscriber implements EventListener {
|
|
22
|
+
static final String NOTIFICATION_EVENT_KEY = "app.notifee.notification-event";
|
|
23
|
+
static final String FOREGROUND_NOTIFICATION_TASK_KEY =
|
|
24
|
+
"app.notifee.foreground-service-headless-task";
|
|
25
|
+
|
|
26
|
+
private static final String KEY_TYPE = "type";
|
|
27
|
+
private static final String KEY_DETAIL = "detail";
|
|
28
|
+
private static final String KEY_BLOCKED = "blocked";
|
|
29
|
+
private static final String KEY_HEADLESS = "headless";
|
|
30
|
+
private static final String KEY_NOTIFICATION = "notification";
|
|
31
|
+
|
|
32
|
+
private static final String KEY_DETAIL_PRESS_ACTION = "pressAction";
|
|
33
|
+
private static final String KEY_DETAIL_INPUT = "input";
|
|
34
|
+
|
|
35
|
+
@Override
|
|
36
|
+
public void onNotificationEvent(NotificationEvent notificationEvent) {
|
|
37
|
+
WritableMap eventMap = Arguments.createMap();
|
|
38
|
+
WritableMap eventDetailMap = Arguments.createMap();
|
|
39
|
+
eventMap.putInt(KEY_TYPE, notificationEvent.getType());
|
|
40
|
+
|
|
41
|
+
eventDetailMap.putMap(
|
|
42
|
+
KEY_NOTIFICATION, Arguments.fromBundle(notificationEvent.getNotification().toBundle()));
|
|
43
|
+
|
|
44
|
+
Bundle extras = notificationEvent.getExtras();
|
|
45
|
+
if (extras != null) {
|
|
46
|
+
Bundle pressAction = extras.getBundle(KEY_DETAIL_PRESS_ACTION);
|
|
47
|
+
if (pressAction != null) {
|
|
48
|
+
eventDetailMap.putMap(KEY_DETAIL_PRESS_ACTION, Arguments.fromBundle(pressAction));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
String input = extras.getString(KEY_DETAIL_INPUT);
|
|
52
|
+
if (input != null) {
|
|
53
|
+
eventDetailMap.putString(KEY_DETAIL_INPUT, input);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
eventMap.putMap(KEY_DETAIL, eventDetailMap);
|
|
58
|
+
|
|
59
|
+
if (isAppInForeground()) {
|
|
60
|
+
eventMap.putBoolean(KEY_HEADLESS, false);
|
|
61
|
+
NotifeeReactUtils.sendEvent(NOTIFICATION_EVENT_KEY, eventMap);
|
|
62
|
+
} else {
|
|
63
|
+
eventMap.putBoolean(KEY_HEADLESS, true);
|
|
64
|
+
NotifeeReactUtils.startHeadlessTask(NOTIFICATION_EVENT_KEY, eventMap, 60000, null);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@Override
|
|
69
|
+
public void onLogEvent(LogEvent logEvent) {
|
|
70
|
+
// TODO
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Override
|
|
74
|
+
public void onBlockStateEvent(BlockStateEvent blockStateEvent) {
|
|
75
|
+
WritableMap eventMap = Arguments.createMap();
|
|
76
|
+
WritableMap eventDetailMap = Arguments.createMap();
|
|
77
|
+
|
|
78
|
+
eventMap.putInt(KEY_TYPE, blockStateEvent.getType());
|
|
79
|
+
|
|
80
|
+
int type = blockStateEvent.getType();
|
|
81
|
+
|
|
82
|
+
if (type == BlockStateEvent.TYPE_CHANNEL_BLOCKED
|
|
83
|
+
|| type == BlockStateEvent.TYPE_CHANNEL_GROUP_BLOCKED) {
|
|
84
|
+
String mapKey = type == BlockStateEvent.TYPE_CHANNEL_BLOCKED ? "channel" : "channelGroup";
|
|
85
|
+
Bundle channelOrGroupBundle = blockStateEvent.getChannelOrGroupBundle();
|
|
86
|
+
if (channelOrGroupBundle != null) {
|
|
87
|
+
eventDetailMap.putMap(
|
|
88
|
+
mapKey, Arguments.fromBundle(blockStateEvent.getChannelOrGroupBundle()));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (type == BlockStateEvent.TYPE_APP_BLOCKED) {
|
|
93
|
+
eventDetailMap.putBoolean(KEY_BLOCKED, blockStateEvent.isBlocked());
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
eventMap.putMap(KEY_DETAIL, eventDetailMap);
|
|
97
|
+
|
|
98
|
+
if (isAppInForeground()) {
|
|
99
|
+
eventMap.putBoolean(KEY_HEADLESS, false);
|
|
100
|
+
NotifeeReactUtils.sendEvent(NOTIFICATION_EVENT_KEY, eventMap);
|
|
101
|
+
} else {
|
|
102
|
+
eventMap.putBoolean(KEY_HEADLESS, true);
|
|
103
|
+
NotifeeReactUtils.startHeadlessTask(
|
|
104
|
+
NOTIFICATION_EVENT_KEY, eventMap, 0, blockStateEvent::setCompletionResult);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@Override
|
|
109
|
+
public void onForegroundServiceEvent(ForegroundServiceEvent foregroundServiceEvent) {
|
|
110
|
+
NotificationModel notificationBundle = foregroundServiceEvent.getNotification();
|
|
111
|
+
|
|
112
|
+
WritableMap eventMap = Arguments.createMap();
|
|
113
|
+
eventMap.putMap(KEY_NOTIFICATION, Arguments.fromBundle(notificationBundle.toBundle()));
|
|
114
|
+
|
|
115
|
+
NotifeeReactUtils.startHeadlessTask(
|
|
116
|
+
FOREGROUND_NOTIFICATION_TASK_KEY, eventMap, 0, foregroundServiceEvent::setCompletionResult);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
package io.invertase.notifee;
|
|
6
|
+
|
|
7
|
+
import android.content.Context;
|
|
8
|
+
import android.content.pm.PackageInfo;
|
|
9
|
+
import android.content.pm.PackageManager;
|
|
10
|
+
import app.notifee.core.InitProvider;
|
|
11
|
+
import app.notifee.core.Notifee;
|
|
12
|
+
import com.facebook.react.modules.systeminfo.ReactNativeVersion;
|
|
13
|
+
import java.util.Map;
|
|
14
|
+
|
|
15
|
+
public class NotifeeInitProvider extends InitProvider {
|
|
16
|
+
@Override
|
|
17
|
+
public boolean onCreate() {
|
|
18
|
+
boolean onCreate = super.onCreate();
|
|
19
|
+
|
|
20
|
+
Notifee.initialize(new NotifeeEventSubscriber());
|
|
21
|
+
return onCreate;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private String getApplicationVersionString() {
|
|
25
|
+
String version = "unknown";
|
|
26
|
+
Context context = this.getContext();
|
|
27
|
+
if (context != null) {
|
|
28
|
+
PackageManager pm = context.getPackageManager();
|
|
29
|
+
try {
|
|
30
|
+
PackageInfo pInfo = pm.getPackageInfo(context.getPackageName(), 0);
|
|
31
|
+
version = pInfo.versionName;
|
|
32
|
+
} catch (Exception e) {
|
|
33
|
+
// is there anything useful to log the unbelievably unexpected inability to get package
|
|
34
|
+
// info?
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return version;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private String getReactNativeVersionString() {
|
|
42
|
+
Map<String, Object> versionMap = ReactNativeVersion.VERSION;
|
|
43
|
+
int major = (int) versionMap.get("major");
|
|
44
|
+
int minor = (int) versionMap.get("minor");
|
|
45
|
+
int patch = (int) versionMap.get("patch");
|
|
46
|
+
String prerelease = (String) versionMap.get("prerelease");
|
|
47
|
+
|
|
48
|
+
String versionName = major + "." + minor + "." + patch;
|
|
49
|
+
if (prerelease != null) {
|
|
50
|
+
versionName += "." + prerelease;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return versionName;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
package io.invertase.notifee;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.ReactPackage;
|
|
8
|
+
import com.facebook.react.bridge.NativeModule;
|
|
9
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
11
|
+
import java.util.ArrayList;
|
|
12
|
+
import java.util.Collections;
|
|
13
|
+
import java.util.List;
|
|
14
|
+
import javax.annotation.Nonnull;
|
|
15
|
+
|
|
16
|
+
public class NotifeePackage implements ReactPackage {
|
|
17
|
+
@Nonnull
|
|
18
|
+
@Override
|
|
19
|
+
public List<NativeModule> createNativeModules(@Nonnull ReactApplicationContext reactContext) {
|
|
20
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
21
|
+
modules.add(new NotifeeApiModule(reactContext));
|
|
22
|
+
return modules;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Nonnull
|
|
26
|
+
@Override
|
|
27
|
+
public List<ViewManager> createViewManagers(@Nonnull ReactApplicationContext reactContext) {
|
|
28
|
+
return Collections.emptyList();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
package io.invertase.notifee;
|
|
6
|
+
|
|
7
|
+
import static io.invertase.notifee.HeadlessTask.getReactContext;
|
|
8
|
+
|
|
9
|
+
import android.annotation.SuppressLint;
|
|
10
|
+
import android.content.Context;
|
|
11
|
+
import android.os.Build;
|
|
12
|
+
import android.os.Bundle;
|
|
13
|
+
import android.util.Log;
|
|
14
|
+
import androidx.annotation.Nullable;
|
|
15
|
+
import androidx.lifecycle.Lifecycle;
|
|
16
|
+
import androidx.lifecycle.ProcessLifecycleOwner;
|
|
17
|
+
import app.notifee.core.EventSubscriber;
|
|
18
|
+
import com.facebook.react.bridge.Arguments;
|
|
19
|
+
import com.facebook.react.bridge.Promise;
|
|
20
|
+
import com.facebook.react.bridge.ReactContext;
|
|
21
|
+
import com.facebook.react.bridge.WritableArray;
|
|
22
|
+
import com.facebook.react.bridge.WritableMap;
|
|
23
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
24
|
+
import java.lang.reflect.Method;
|
|
25
|
+
import java.util.List;
|
|
26
|
+
|
|
27
|
+
class NotifeeReactUtils {
|
|
28
|
+
public static final HeadlessTask headlessTaskManager = new HeadlessTask();
|
|
29
|
+
|
|
30
|
+
static void promiseResolver(Promise promise, Exception e, Bundle bundle) {
|
|
31
|
+
if (e != null) {
|
|
32
|
+
// TODO custom error class with message/code
|
|
33
|
+
promise.reject(e);
|
|
34
|
+
} else if (bundle != null) {
|
|
35
|
+
promise.resolve(Arguments.fromBundle(bundle));
|
|
36
|
+
} else {
|
|
37
|
+
promise.resolve(null);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static void promiseResolver(Promise promise, Exception e, List<Bundle> bundleList) {
|
|
42
|
+
if (e != null) {
|
|
43
|
+
// TODO custom error class with message/code
|
|
44
|
+
promise.reject(e);
|
|
45
|
+
} else {
|
|
46
|
+
WritableArray writableArray = Arguments.createArray();
|
|
47
|
+
for (Bundle bundle : bundleList) {
|
|
48
|
+
writableArray.pushMap(Arguments.fromBundle(bundle));
|
|
49
|
+
}
|
|
50
|
+
promise.resolve(writableArray);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static void promiseBooleanResolver(Promise promise, Exception e, Boolean bool) {
|
|
55
|
+
if (e != null) {
|
|
56
|
+
// TODO custom error class with message/code
|
|
57
|
+
promise.reject(e);
|
|
58
|
+
} else {
|
|
59
|
+
promise.resolve(bool);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static void promiseStringListResolver(Promise promise, Exception e, List<String> stringList) {
|
|
64
|
+
if (e != null) {
|
|
65
|
+
// TODO custom error class with message/code
|
|
66
|
+
promise.reject(e);
|
|
67
|
+
} else {
|
|
68
|
+
WritableArray writableArray = Arguments.createArray();
|
|
69
|
+
for (String string : stringList) {
|
|
70
|
+
writableArray.pushString(string);
|
|
71
|
+
}
|
|
72
|
+
promise.resolve(writableArray);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static void promiseResolver(Promise promise, Exception e) {
|
|
77
|
+
if (e != null) {
|
|
78
|
+
// TODO custom error class with message/code
|
|
79
|
+
promise.reject(e);
|
|
80
|
+
} else {
|
|
81
|
+
promise.resolve(null);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static void startHeadlessTask(
|
|
86
|
+
String taskName,
|
|
87
|
+
WritableMap taskData,
|
|
88
|
+
long taskTimeout,
|
|
89
|
+
@Nullable HeadlessTask.GenericCallback taskCompletionCallback) {
|
|
90
|
+
|
|
91
|
+
HeadlessTask.TaskConfig config =
|
|
92
|
+
new HeadlessTask.TaskConfig(taskName, taskTimeout, taskData, taskCompletionCallback);
|
|
93
|
+
headlessTaskManager.startTask(EventSubscriber.getContext(), config);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static void sendEvent(String eventName, WritableMap eventMap) {
|
|
97
|
+
try {
|
|
98
|
+
ReactContext reactContext = getReactContext(EventSubscriber.getContext());
|
|
99
|
+
|
|
100
|
+
if (reactContext == null || !reactContext.hasActiveCatalystInstance()) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
reactContext
|
|
105
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
106
|
+
.emit(eventName, eventMap);
|
|
107
|
+
|
|
108
|
+
} catch (Exception e) {
|
|
109
|
+
Log.e("SEND_EVENT", "", e);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static boolean isAppInForeground() {
|
|
114
|
+
return ProcessLifecycleOwner.get()
|
|
115
|
+
.getLifecycle()
|
|
116
|
+
.getCurrentState()
|
|
117
|
+
.isAtLeast(Lifecycle.State.RESUMED);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static void hideNotificationDrawer() {
|
|
121
|
+
Context context = EventSubscriber.getContext();
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
@SuppressLint("WrongConstant")
|
|
125
|
+
Object service = context.getSystemService("statusbar");
|
|
126
|
+
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
|
|
127
|
+
Method collapse =
|
|
128
|
+
statusbarManager.getMethod((Build.VERSION.SDK_INT >= 17) ? "collapsePanels" : "collapse");
|
|
129
|
+
collapse.setAccessible(true);
|
|
130
|
+
collapse.invoke(service);
|
|
131
|
+
} catch (Exception e) {
|
|
132
|
+
Log.e("HIDE_NOTIF_DRAWER", "", e);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|