1717import android .os .Build ;
1818import android .os .Bundle ;
1919import android .support .v4 .app .NotificationCompat ;
20+ import android .support .v4 .content .LocalBroadcastManager ;
2021import android .util .Log ;
2122
2223import com .facebook .react .bridge .ReadableMap ;
2324
2425import org .json .JSONArray ;
2526import org .json .JSONException ;
27+ import org .json .JSONObject ;
2628
2729import com .microsoft .windowsazure .notifications .NotificationsHandler ;
2830
31+ import java .util .Set ;
32+
2933public class ReactNativeNotificationsHandler extends NotificationsHandler {
30- private static final String LOG_TAG = "AzureNotificationHub" ;
34+ public static final String TAG = "ReactNativeNotificationsHandler" ;
35+
3136 private static final long DEFAULT_VIBRATION = 300L ;
3237
3338 private Context context ;
@@ -36,6 +41,21 @@ public class ReactNativeNotificationsHandler extends NotificationsHandler {
3641 public void onReceive (Context context , Bundle bundle ) {
3742 this .context = context ;
3843 sendNotification (bundle );
44+
45+ JSONObject json = new JSONObject ();
46+ Set <String > keys = bundle .keySet ();
47+ for (String key : keys ) {
48+ try {
49+ json .put (key , bundle .get (key ));
50+ } catch (JSONException e ) {
51+ }
52+ }
53+
54+ LocalBroadcastManager localBroadcastManager = LocalBroadcastManager .getInstance (context );
55+ Intent event = new Intent (TAG );
56+ event .putExtra ("event" , ReactNativeNotificationHubModule .DEVICE_NOTIF_EVENT );
57+ event .putExtra ("data" , json .toString ());
58+ localBroadcastManager .sendBroadcast (event );
3959 }
4060
4161 private Class getMainActivityClass () {
@@ -58,18 +78,18 @@ private void sendNotification(Bundle bundle) {
5878 try {
5979 Class intentClass = getMainActivityClass ();
6080 if (intentClass == null ) {
61- Log .e (LOG_TAG , "No activity class found for the notification" );
81+ Log .e (TAG , "No activity class found for the notification" );
6282 return ;
6383 }
6484
6585 if (bundle .getString ("message" ) == null ) {
66- Log .e (LOG_TAG , "No message specified for the notification" );
86+ Log .e (TAG , "No message specified for the notification" );
6787 return ;
6888 }
6989
7090 String notificationIdString = bundle .getString ("id" );
7191 if (notificationIdString == null ) {
72- Log .e (LOG_TAG , "No notification ID specified for the notification" );
92+ Log .e (TAG , "No notification ID specified for the notification" );
7393 return ;
7494 }
7595
@@ -211,7 +231,7 @@ private void sendNotification(Bundle bundle) {
211231 try {
212232 actionsArray = bundle .getString ("actions" ) != null ? new JSONArray (bundle .getString ("actions" )) : null ;
213233 } catch (JSONException e ) {
214- Log .e (LOG_TAG , "Exception while converting actions to JSON object." , e );
234+ Log .e (TAG , "Exception while converting actions to JSON object." , e );
215235 }
216236
217237 if (actionsArray != null ) {
@@ -224,7 +244,7 @@ private void sendNotification(Bundle bundle) {
224244 try {
225245 action = actionsArray .getString (i );
226246 } catch (JSONException e ) {
227- Log .e (LOG_TAG , "Exception while getting action from actionsArray." , e );
247+ Log .e (TAG , "Exception while getting action from actionsArray." , e );
228248 continue ;
229249 }
230250
@@ -249,7 +269,7 @@ private void sendNotification(Bundle bundle) {
249269 notificationManager .notify (notificationID , info );
250270 }
251271 } catch (Exception e ) {
252- Log .e (LOG_TAG , "failed to send push notification" , e );
272+ Log .e (TAG , "failed to send push notification" , e );
253273 }
254274 }
255275
0 commit comments