@Override public void onReceive(final Context context, Intent intent) { ApiHandler.Initialize(context); final DataAccessObject dao = new DataAccessObject(context); if (intent.hasExtra("newMessage")) { String messageId = intent.getStringExtra("newMessage"); try { ApiHandler.RetrieveMessage( Long.parseLong(messageId), new Callback<Message>() { @Override public void Invoke(Message result) { dao.WriteMessageToUserConversation(result, false); NotificationHandler.SendNotification( result.getFrom(), result.getContnet(), context); } }); } catch (NumberFormatException e) { Log.e(getClass().toString(), "Could not parse messageId as long: " + e.getMessage()); } } else if (intent.hasExtra("message")) { try { String m = intent.getStringExtra("message"); JSONObject json = new JSONObject(m); GcmMessageHandler.HandleMessage(context, json, m); } catch (JSONException e) { Log.e(getClass().toString(), e.getMessage()); } } }
protected void onPostExecute(String response) { if (response != null && !response.isEmpty()) { handler.execute(response); } else { Toast.makeText(app, "Connection Failure", Toast.LENGTH_SHORT).show(); } handler.postExecute(); }