2929import com .facebook .react .modules .core .DeviceEventManagerModule ;
3030
3131
32+ import org .json .JSONException ;
3233import org .json .JSONObject ;
3334
3435import java .lang .reflect .Field ;
3738import java .text .SimpleDateFormat ;
3839import java .util .Date ;
3940import java .util .HashSet ;
41+ import java .util .Iterator ;
4042import java .util .LinkedHashSet ;
4143import java .util .List ;
4244import java .util .Set ;
@@ -181,21 +183,36 @@ private static void sendEvent() {
181183 switch (mEvent ) {
182184 case RECEIVE_CUSTOM_MESSAGE :
183185 WritableMap map = Arguments .createMap ();
184- map .putInt ("id" , mCachedBundle .getInt (JPushInterface .EXTRA_NOTIFICATION_ID ));
185- map .putString ("message" , mCachedBundle .getString (JPushInterface .EXTRA_MESSAGE ));
186- map .putString ("content" , mCachedBundle .getString (JPushInterface .EXTRA_MESSAGE ));
187- map .putString ("content_type" , mCachedBundle .getString (JPushInterface .EXTRA_CONTENT_TYPE ));
188- map .putString ("title" , mCachedBundle .getString (JPushInterface .EXTRA_TITLE ));
186+ WritableMap extrasMap =Arguments .createMap ();
189187 map .putString ("extras" , mCachedBundle .getString (JPushInterface .EXTRA_EXTRA ));
188+ map .putString ("content_type" , mCachedBundle .getString (JPushInterface .EXTRA_CONTENT_TYPE ));
189+ map .putString ("content" , mCachedBundle .getString (JPushInterface .EXTRA_MESSAGE ));
190+ map .putString ("title" , mCachedBundle .getString (JPushInterface .EXTRA_NOTIFICATION_TITLE ));
191+ map .putString ("id" , mCachedBundle .getString (JPushInterface .EXTRA_MSG_ID ));
190192 mRAC .getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class )
191193 .emit (mEvent , map );
192194 break ;
193195 case RECEIVE_NOTIFICATION :
194196 case OPEN_NOTIFICATION :
195197 map = Arguments .createMap ();
196- map .putInt ("id" , mCachedBundle .getInt (JPushInterface .EXTRA_NOTIFICATION_ID ));
197- map .putString ("alertContent" , mCachedBundle .getString (JPushInterface .EXTRA_ALERT ));
198- map .putString ("extras" , mCachedBundle .getString (JPushInterface .EXTRA_EXTRA ));
198+ extrasMap =Arguments .createMap ();
199+ try {
200+ String string = mCachedBundle .getString (JPushInterface .EXTRA_EXTRA );
201+ JSONObject jsonObject = new JSONObject (string );
202+ Iterator it = jsonObject .keys ();
203+ while (it .hasNext ()) {
204+ String key = (String )it .next ();
205+ String value = jsonObject .getString (key );
206+ extrasMap .putString (key ,value );
207+ }
208+ } catch (JSONException e ) {
209+ e .printStackTrace ();
210+ }
211+ map .putMap ("extras" ,extrasMap );
212+ map .putString ("content_type" , mCachedBundle .getString (JPushInterface .EXTRA_ALERT_TYPE ));
213+ map .putString ("content" , mCachedBundle .getString (JPushInterface .EXTRA_ALERT ));
214+ map .putString ("title" , mCachedBundle .getString (JPushInterface .EXTRA_NOTIFICATION_TITLE ));
215+ map .putString ("id" , mCachedBundle .getString (JPushInterface .EXTRA_MSG_ID ));
199216 mRAC .getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class )
200217 .emit (mEvent , map );
201218 break ;
@@ -599,12 +616,9 @@ public JPushReceiver() {
599616
600617 @ Override
601618 public void onReceive (Context context , Intent data ) {
602-
603619 if (JPushInterface .ACTION_MESSAGE_RECEIVED .equals (data .getAction ())) {
604620 mCachedBundle = data .getExtras ();
605621 try {
606- String message = data .getStringExtra (JPushInterface .EXTRA_MESSAGE );
607- Logger .i (TAG , "收到自定义消息: " + message );
608622 mEvent = RECEIVE_CUSTOM_MESSAGE ;
609623 if (mRAC != null ) {
610624 sendEvent ();
@@ -615,12 +629,6 @@ public void onReceive(Context context, Intent data) {
615629 } else if (JPushInterface .ACTION_NOTIFICATION_RECEIVED .equals (data .getAction ())) {
616630 mCachedBundle = data .getExtras ();
617631 try {
618- // 通知内容
619- String alertContent = mCachedBundle .getString (JPushInterface .EXTRA_ALERT );
620- // extra 字段的 json 字符串
621- String extras = mCachedBundle .getString (JPushInterface .EXTRA_EXTRA );
622- Logger .i (TAG , "收到推送下来的通知: " + alertContent );
623- Logger .i (TAG , "extras: " + extras );
624632 mEvent = RECEIVE_NOTIFICATION ;
625633 if (mRAC != null ) {
626634 sendEvent ();
@@ -631,15 +639,6 @@ public void onReceive(Context context, Intent data) {
631639 } else if (JPushInterface .ACTION_NOTIFICATION_OPENED .equals (data .getAction ())) {
632640 mCachedBundle = data .getExtras ();
633641 try {
634- Logger .d (TAG , "用户点击打开了通知" );
635- // 通知内容
636- String alertContent = mCachedBundle .getString (JPushInterface .EXTRA_ALERT );
637- // extra 字段的 json 字符串
638- String extras = mCachedBundle .getString (JPushInterface .EXTRA_EXTRA );
639- Intent intent = context .getPackageManager ().getLaunchIntentForPackage (context .getPackageName ());
640- intent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK | Intent .FLAG_ACTIVITY_SINGLE_TOP | Intent .FLAG_ACTIVITY_CLEAR_TOP );
641- intent .putExtras (mCachedBundle );
642- context .startActivity (intent );
643642 mEvent = OPEN_NOTIFICATION ;
644643 if (mRAC != null ) {
645644 sendEvent ();
0 commit comments