55import android .content .Context ;
66import android .content .Intent ;
77import android .content .IntentFilter ;
8+ import android .os .Bundle ;
89import android .support .v4 .content .LocalBroadcastManager ;
910
11+ import com .facebook .react .bridge .LifecycleEventListener ;
1012import com .facebook .react .modules .core .DeviceEventManagerModule ;
1113import com .google .android .gms .common .ConnectionResult ;
1214import com .google .android .gms .common .GoogleApiAvailability ;
2325import com .facebook .react .bridge .ReadableMap ;
2426import com .facebook .react .bridge .UiThreadUtil ;
2527
26- public class ReactNativeNotificationHubModule extends ReactContextBaseJavaModule {
28+ public class ReactNativeNotificationHubModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
2729 public static final String NOTIF_REGISTER_AZURE_HUB_EVENT = "azureNotificationHubRegistered" ;
2830 public static final String NOTIF_AZURE_HUB_REGISTRATION_ERROR_EVENT = "azureNotificationHubRegistrationError" ;
2931 public static final String DEVICE_NOTIF_EVENT = "remoteNotificationReceived" ;
3032
3133 private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000 ;
34+ private static final int NOTIFICATION_DELAY_ON_START = 3000 ;
3235
3336 private static final String ERROR_INVALID_ARGUMENTS = "E_INVALID_ARGUMENTS" ;
3437 private static final String ERROR_PLAY_SERVICES = "E_PLAY_SERVICES" ;
@@ -45,6 +48,7 @@ public ReactNativeNotificationHubModule(ReactApplicationContext reactContext) {
4548 LocalBroadcastManager localBroadcastManager = LocalBroadcastManager .getInstance (reactContext );
4649 localBroadcastManager .registerReceiver (mLocalBroadcastReceiver , new IntentFilter (ReactNativeRegistrationIntentService .TAG ));
4750 localBroadcastManager .registerReceiver (mLocalBroadcastReceiver , new IntentFilter (ReactNativeNotificationsHandler .TAG ));
51+ reactContext .addLifecycleEventListener (this );
4852 }
4953
5054 @ Override
@@ -128,6 +132,23 @@ public void unregister(Promise promise) {
128132 }
129133 }
130134
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 () {}
131152 public class LocalBroadcastReceiver extends BroadcastReceiver {
132153 @ Override
133154 public void onReceive (Context context , Intent intent ) {
0 commit comments