@Override public T execute( Context context, String requestUrl, EmptyHttpRequest request, Class<T> classOfT, HttpResponseFilter filter) { Response response = LiteHttpClient.getInstance(context) .execute(new Request(requestUrl).setMethod(HttpMethod.Get)); return HttpCommonUtil.onFinish( HttpCommonUtil.getResponseString(response), classOfT, null, filter); }
public void poll() { HttpAsyncExecutor asyncExecutor = HttpAsyncExecutor.newInstance(LiteHttpClient.newApacheHttpClient(this)); MyHttpRequest request = new MyHttpRequest(URLContainer.getPollURL()); asyncExecutor.execute( request, new HttpResponseHandler() { @Override protected void onSuccess(Response res, HttpStatus status, NameValuePair[] headers) { PollMessage message = res.getObject(PollMessage.class); if (message == null) return; sendBroadcast(new Intent(MainActivity.ACTION_REFRESH_COUNTER)); sendBroadcast(new Intent(MainActivity.ACTION_REFRESH_BUTTON)); sendBroadcast(new Intent(MainActivity.ACTION_REFRESH_UPDATE)); if (Params.unread_count != message.unread) { if (canNotify && Params.unread_count < message.unread) { notif.icon = R.drawable.logo_notification; notif.contentView.setImageViewResource( R.id.content_view_image, R.drawable.ic_message); notif.contentView.setTextViewText( R.id.content_view_title, getString(R.string.app_name)); notif.contentView.setTextViewText( R.id.content_view_text, getString(R.string.you_have) + message.unread + getString(R.string.new_unread_message)); notif.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_AUTO_CANCEL; Intent intent = new Intent(PollService.this, LauncherActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(PollService.this, 0, intent, 0); notif.contentIntent = pendingIntent; manager.notify(Params.MESSAGE_NOTIFICATION_ID, notif); } Params.unread_count = message.unread; Params.refresh_mail = true; } Params.message = message; } @Override protected void onFailure(Response res, HttpException e) {} }); }