public void doOnMessageReceive(String message) { string me = GetString (Resource.String.on_message); me = me.Replace("%s", message); mGeneralStatus.Text = me; // mGeneralStatus.SetText(GetString(Resource.String.on_message, message)); // Parse custom JSON data string. // You can set background color with custom JSON data in the following format: { "r" : "10", "g" : "200", "b" : "100" } // Or open specific screen of the app with custom page ID (set ID in the { "id" : "2" } format) try { JSONObject messageJson = new JSONObject(message); JSONObject customJson = new JSONObject(messageJson.GetString("u")); if (customJson.Has("r") && customJson.Has("g") && customJson.Has("b")) { int r = customJson.GetInt("r"); int g = customJson.GetInt("g"); int b = customJson.GetInt("b"); Window.DecorView.FindViewById<View>(Android.Resource.Id.Content).SetBackgroundColor(Android.Graphics.Color.Rgb(r, g, b)); } if (customJson.Has("id")) { Intent intent = new Intent(this, typeof(SecondActivity)); intent.PutExtra(PushManager.PushReceiveEvent, messageJson.ToString()); StartActivity(intent); } } catch (JSONException e) { e.PrintStackTrace (); } }
private TimeSpan JsonToTimeSpan(JSONObject time) { var days = time.GetInt("days"); var hours = time.GetInt("hours"); var minutes = time.GetInt("minutes"); var seconds = time.GetInt("seconds"); var milliseconds = time.GetInt("milliseconds"); return new TimeSpan(days, hours, minutes, seconds, milliseconds); }
public void onMessage(string data) { try { JSONObject json = new JSONObject(data); string type = (string)json.Get("type"); if (type.Equals("candidate")) { IceCandidate candidate = new IceCandidate((string)json.Get("id"), json.GetInt("label"), (string)json.Get("candidate")); if (outerInstance.queuedRemoteCandidates != null) { outerInstance.queuedRemoteCandidates.AddLast(candidate); } else { outerInstance.pc.AddIceCandidate(candidate); } } else if (type.Equals("answer") || type.Equals("offer")) { SessionDescription sdp = new SessionDescription(SessionDescription.SessionDescriptionType.FromCanonicalForm(type), outerInstance.preferISAC((string)json.Get("sdp"))); outerInstance.pc.SetRemoteDescription(outerInstance.sdpObserver, sdp); } else if (type.Equals("bye")) { outerInstance.logAndToast("Remote end hung up; dropping PeerConnection"); outerInstance.disconnectAndExit(); } else { throw new Exception("Unexpected message: " + data); } } catch (JSONException e) { throw new Exception("Error", e); } }
public static Question FromJSon (JSONObject questionObject, int questionIndex) { try { string question = questionObject.GetString (JsonUtils.JSON_FIELD_QUESTION); JSONArray answersJsonArray = questionObject.GetJSONArray (JsonUtils.JSON_FIELD_ANSWERS); string[] answers = new string[JsonUtils.NUM_ANSWER_CHOICES]; for (int j = 0; j < answersJsonArray.Length (); j++) { answers [j] = answersJsonArray.GetString (j); } int correctIndex = questionObject.GetInt (JsonUtils.JSON_FIELD_CORRECT_INDEX); return new Question (question, questionIndex, answers, correctIndex); } catch (JSONException) { return null; } }