1111
1212import com .facebook .react .bridge .ActivityEventListener ;
1313import com .facebook .react .bridge .LifecycleEventListener ;
14- import com .facebook .react .modules .core .DeviceEventManagerModule ;
1514import com .google .android .gms .common .ConnectionResult ;
1615import com .google .android .gms .common .GoogleApiAvailability ;
1716
@@ -65,27 +64,27 @@ public boolean getIsForeground() {
6564 @ ReactMethod
6665 public void register (ReadableMap config , Promise promise ) {
6766 ReactNativeNotificationHubUtil notificationHubUtil = ReactNativeNotificationHubUtil .getInstance ();
68- String connectionString = config .getString ("connectionString" );
67+ String connectionString = config .getString (KEY_REGISTRATION_CONNECTIONSTRING );
6968 if (connectionString == null ) {
7069 promise .reject (ERROR_INVALID_ARGUMENTS , ERROR_INVALID_CONNECTION_STRING );
7170 return ;
7271 }
7372
74- String hubName = config .getString ("hubName" );
73+ String hubName = config .getString (KEY_REGISTRATION_HUBNAME );
7574 if (hubName == null ) {
7675 promise .reject (ERROR_INVALID_ARGUMENTS , ERROR_INVALID_HUBNAME );
7776 return ;
7877 }
7978
80- String senderID = config .getString ("senderID" );
79+ String senderID = config .getString (KEY_REGISTRATION_SENDERID );
8180 if (senderID == null ) {
8281 promise .reject (ERROR_INVALID_ARGUMENTS , ERROR_INVALID_SENDER_ID );
8382 return ;
8483 }
8584
8685 String [] tags = null ;
87- if (config .hasKey ("tags" ) && !config .isNull ("tags" )) {
88- ReadableArray tagsJson = config .getArray ("tags" );
86+ if (config .hasKey (KEY_REGISTRATION_TAGS ) && !config .isNull (KEY_REGISTRATION_TAGS )) {
87+ ReadableArray tagsJson = config .getArray (KEY_REGISTRATION_TAGS );
8988 tags = new String [tagsJson .size ()];
9089 for (int i = 0 ; i < tagsJson .size (); ++i ) {
9190 tags [i ] = tagsJson .getString (i );
@@ -98,23 +97,28 @@ public void register(ReadableMap config, Promise promise) {
9897 notificationHubUtil .setSenderID (reactContext , senderID );
9998 notificationHubUtil .setTags (reactContext , tags );
10099
101- if (config .hasKey ("channelImportance" )) {
102- int channelImportance = config .getInt ("channelImportance" );
100+ if (config .hasKey (KEY_REGISTRATION_CHANNELNAME )) {
101+ String channelName = config .getString (KEY_REGISTRATION_CHANNELNAME );
102+ notificationHubUtil .setChannelName (reactContext , channelName );
103+ }
104+
105+ if (config .hasKey (KEY_REGISTRATION_CHANNELIMPORTANCE )) {
106+ int channelImportance = config .getInt (KEY_REGISTRATION_CHANNELIMPORTANCE );
103107 notificationHubUtil .setChannelImportance (reactContext , channelImportance );
104108 }
105109
106- if (config .hasKey ("channelShowBadge" )) {
107- boolean channelShowBadge = config .getBoolean ("channelShowBadge" );
110+ if (config .hasKey (KEY_REGISTRATION_CHANNELSHOWBADGE )) {
111+ boolean channelShowBadge = config .getBoolean (KEY_REGISTRATION_CHANNELSHOWBADGE );
108112 notificationHubUtil .setChannelShowBadge (reactContext , channelShowBadge );
109113 }
110114
111- if (config .hasKey ("channelEnableLights" )) {
112- boolean channelEnableLights = config .getBoolean ("channelEnableLights" );
115+ if (config .hasKey (KEY_REGISTRATION_CHANNELENABLELIGHTS )) {
116+ boolean channelEnableLights = config .getBoolean (KEY_REGISTRATION_CHANNELENABLELIGHTS );
113117 notificationHubUtil .setChannelEnableLights (reactContext , channelEnableLights );
114118 }
115119
116- if (config .hasKey ("channelEnableVibration" )) {
117- boolean channelEnableVibration = config .getBoolean ("channelEnableVibration" );
120+ if (config .hasKey (KEY_REGISTRATION_CHANNELENABLEVIBRATION )) {
121+ boolean channelEnableVibration = config .getBoolean (KEY_REGISTRATION_CHANNELENABLEVIBRATION );
118122 notificationHubUtil .setChannelEnableVibration (reactContext , channelEnableVibration );
119123 }
120124
@@ -170,9 +174,9 @@ public void onHostResume() {
170174 if (activity != null ) {
171175 Intent intent = activity .getIntent ();
172176 if (intent != null ) {
173- Bundle bundle = intent . getBundleExtra ( KEY_INTENT_NOTIFICATION );
177+ Bundle bundle = ReactNativeUtil . getBundleFromIntent ( intent );
174178 if (bundle != null ) {
175- intent . removeExtra ( KEY_INTENT_NOTIFICATION );
179+ ReactNativeUtil . removeNotificationFromIntent ( intent );
176180 bundle .putBoolean (KEY_REMOTE_NOTIFICATION_FOREGROUND , false );
177181 bundle .putBoolean (KEY_REMOTE_NOTIFICATION_USER_INTERACTION , true );
178182 bundle .putBoolean (KEY_REMOTE_NOTIFICATION_COLDSTART , true );
@@ -194,7 +198,7 @@ public void onHostDestroy() {
194198
195199 @ Override
196200 public void onNewIntent (Intent intent ) {
197- Bundle bundle = intent . getBundleExtra ( KEY_INTENT_NOTIFICATION );
201+ Bundle bundle = ReactNativeUtil . getBundleFromIntent ( intent );
198202 if (bundle != null ) {
199203 bundle .putBoolean (KEY_REMOTE_NOTIFICATION_FOREGROUND , false );
200204 bundle .putBoolean (KEY_REMOTE_NOTIFICATION_USER_INTERACTION , true );
@@ -211,10 +215,7 @@ public class LocalBroadcastReceiver extends BroadcastReceiver {
211215 @ Override
212216 public void onReceive (Context context , Intent intent ) {
213217 if (getIsForeground ()) {
214- String event = intent .getStringExtra ("event" );
215- String data = intent .getStringExtra ("data" );
216- mReactContext .getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class )
217- .emit (event , data );
218+ ReactNativeUtil .emitIntent (mReactContext , intent );
218219 }
219220 }
220221 }
0 commit comments