5
5
import android .content .Context ;
6
6
import android .content .Intent ;
7
7
import android .content .IntentFilter ;
8
+ import android .os .Bundle ;
8
9
import android .support .v4 .content .LocalBroadcastManager ;
9
10
11
+ import com .facebook .react .bridge .LifecycleEventListener ;
10
12
import com .facebook .react .modules .core .DeviceEventManagerModule ;
11
13
import com .google .android .gms .common .ConnectionResult ;
12
14
import com .google .android .gms .common .GoogleApiAvailability ;
23
25
import com .facebook .react .bridge .ReadableMap ;
24
26
import com .facebook .react .bridge .UiThreadUtil ;
25
27
26
- public class ReactNativeNotificationHubModule extends ReactContextBaseJavaModule {
28
+ public class ReactNativeNotificationHubModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
27
29
public static final String NOTIF_REGISTER_AZURE_HUB_EVENT = "azureNotificationHubRegistered" ;
28
30
public static final String NOTIF_AZURE_HUB_REGISTRATION_ERROR_EVENT = "azureNotificationHubRegistrationError" ;
29
31
public static final String DEVICE_NOTIF_EVENT = "remoteNotificationReceived" ;
30
32
31
33
private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000 ;
34
+ private static final int NOTIFICATION_DELAY_ON_START = 3000 ;
32
35
33
36
private static final String ERROR_INVALID_ARGUMENTS = "E_INVALID_ARGUMENTS" ;
34
37
private static final String ERROR_PLAY_SERVICES = "E_PLAY_SERVICES" ;
@@ -45,6 +48,7 @@ public ReactNativeNotificationHubModule(ReactApplicationContext reactContext) {
45
48
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager .getInstance (reactContext );
46
49
localBroadcastManager .registerReceiver (mLocalBroadcastReceiver , new IntentFilter (ReactNativeRegistrationIntentService .TAG ));
47
50
localBroadcastManager .registerReceiver (mLocalBroadcastReceiver , new IntentFilter (ReactNativeNotificationsHandler .TAG ));
51
+ reactContext .addLifecycleEventListener (this );
48
52
}
49
53
50
54
@ Override
@@ -128,6 +132,23 @@ public void unregister(Promise promise) {
128
132
}
129
133
}
130
134
135
+ @ Override
136
+ public void onHostResume () {
137
+ Activity activity = getCurrentActivity ();
138
+ if (activity != null ) {
139
+ Intent intent = activity .getIntent ();
140
+ if (intent != null ) {
141
+ Bundle bundle = intent .getBundleExtra ("notification" );
142
+ if (bundle != null ) {
143
+ new ReactNativeNotificationsHandler ().sendBroadcast (mReactContext , bundle , NOTIFICATION_DELAY_ON_START );
144
+ }
145
+ }
146
+ }
147
+ }
148
+ @ Override
149
+ public void onHostPause () {}
150
+ @ Override
151
+ public void onHostDestroy () {}
131
152
public class LocalBroadcastReceiver extends BroadcastReceiver {
132
153
@ Override
133
154
public void onReceive (Context context , Intent intent ) {
0 commit comments