1111import com .tencent .android .tpush .XGPushShowedResult ;
1212import com .tencent .android .tpush .XGPushTextMessage ;
1313
14+ import org .json .JSONException ;
15+ import org .json .JSONObject ;
16+
17+ import me .leolin .shortcutbadger .ShortcutBadger ;
18+
1419/**
1520 * 消息接收器
1621 * Created by Jeepeng on 16/8/4.
@@ -25,13 +30,11 @@ public class MessageReceiver extends XGPushBaseReceiver {
2530 */
2631 @ Override
2732 public void onRegisterResult (Context context , int errorCode , XGPushRegisterResult xgPushRegisterResult ) {
28-
2933 if (errorCode == 0 ) {
3034 Intent intent = new Intent (Constants .ACTION_ON_REGISTERED );
3135 intent .putExtra ("token" , xgPushRegisterResult .getToken ());
3236 context .sendBroadcast (intent );
3337 }
34-
3538 }
3639
3740 /**
@@ -77,7 +80,7 @@ public void onTextMessage(Context context, XGPushTextMessage xgPushTextMessage)
7780 Intent intent = new Intent (Constants .ACTION_ON_TEXT_MESSAGE );
7881 intent .putExtra ("title" , xgPushTextMessage .getTitle ());
7982 intent .putExtra ("content" , xgPushTextMessage .getContent ());
80- intent .putExtra ("customContent " , xgPushTextMessage .getCustomContent ());
83+ intent .putExtra ("custom_content " , xgPushTextMessage .getCustomContent ());
8184 context .sendBroadcast (intent );
8285 }
8386
@@ -120,6 +123,16 @@ public void onNotifactionClickedResult(Context context, XGPushClickedResult noti
120123 */
121124 @ Override
122125 public void onNotifactionShowedResult (Context context , XGPushShowedResult xgPushShowedResult ) {
126+ // set app icon badge
127+ try {
128+ JSONObject obj = new JSONObject (xgPushShowedResult .getCustomContent ());
129+ int badge = obj .optInt ("badge" , -1 );
130+ if (badge >= 0 ) {
131+ ShortcutBadger .applyCount (context , badge );
132+ }
133+ } catch (JSONException e ) {
134+ e .printStackTrace ();
135+ }
123136 Intent intent = new Intent (Constants .ACTION_ON_NOTIFICATION_SHOWED );
124137 Bundle bundle = new Bundle ();
125138 bundle .putString ("content" , xgPushShowedResult .getContent ());
0 commit comments