示例#1
0
 //send msg to MainActivity
 private void processCustomMessage(Context context, Bundle bundle)
 {
     if (MainActivity.isForeground)
     {
         string message   = bundle.GetString(JPushInterface.EXTRA_MESSAGE);
         string extras    = bundle.GetString(JPushInterface.EXTRA_EXTRA);
         Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
         msgIntent.PutExtra(MainActivity.KEY_MESSAGE, message);
         if (!ExampleUtil.isEmpty(extras))
         {
             try
             {
                 JSONObject extraJson = new JSONObject(extras);
                 if (extraJson.length() > 0)
                 {
                     msgIntent.PutExtra(MainActivity.KEY_EXTRAS, extras);
                 }
             }
             catch (JSONException)
             {
             }
         }
         //LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
     }
 }
 //send msg to MainActivity
 private void processCustomMessage(Context context, CustomMessage customMessage)
 {
     if (MainActivity.isForeground)
     {
         string message   = customMessage.Message;
         string extras    = customMessage.Extra;
         Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
         msgIntent.PutExtra(MainActivity.KEY_MESSAGE, message);
         if (!ExampleUtil.isEmpty(extras))
         {
             try
             {
                 Newtonsoft.Json.Linq.JObject extraJson = Newtonsoft.Json.Linq.JObject.Parse(extras);
                 if (extraJson != null)
                 {
                     msgIntent.PutExtra(MainActivity.KEY_EXTRAS, extras);
                 }
             }
             catch (Newtonsoft.Json.JsonException ex)
             {
             }
         }
         // LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
     }
 }
 public override void OnReceive(Context context, Intent intent)
 {
     try
     {
         if (MESSAGE_RECEIVED_ACTION.Equals(intent.Action))
         {
             string        messge  = intent.GetStringExtra(KEY_MESSAGE);
             string        extras  = intent.GetStringExtra(KEY_EXTRAS);
             StringBuilder showMsg = new StringBuilder();
             showMsg.Append(KEY_MESSAGE + " : " + messge + "\n");
             if (!ExampleUtil.isEmpty(extras))
             {
                 showMsg.Append(KEY_EXTRAS + " : " + extras + "\n");
             }
             outerInstance.CostomMsg = showMsg.ToString();
         }
     }
     catch (System.Exception ex)
     {
     }
 }