use of org.apache.http.NameValuePair in project Android-Error-Reporter by tomquist.
the class ExceptionReportService method sendReport.
private void sendReport(Intent intent) throws UnsupportedEncodingException, NameNotFoundException {
Log.v(TAG, "Got request to report error: " + intent.toString());
Uri server = getTargetUrl();
boolean isManualReport = intent.getBooleanExtra(EXTRA_MANUAL_REPORT, false);
boolean isReportOnFroyo = isReportOnFroyo();
boolean isFroyoOrAbove = isFroyoOrAbove();
if (isFroyoOrAbove && !isManualReport && !isReportOnFroyo) {
// We don't send automatic reports on froyo or above
Log.d(TAG, "Don't send automatic report on froyo");
return;
}
Set<String> fieldsToSend = getFieldsToSend();
String stacktrace = intent.getStringExtra(EXTRA_STACK_TRACE);
String exception = intent.getStringExtra(EXTRA_EXCEPTION_CLASS);
String message = intent.getStringExtra(EXTRA_MESSAGE);
long availableMemory = intent.getLongExtra(EXTRA_AVAILABLE_MEMORY, -1l);
long totalMemory = intent.getLongExtra(EXTRA_TOTAL_MEMORY, -1l);
String dateTime = intent.getStringExtra(EXTRA_EXCEPTION_TIME);
String threadName = intent.getStringExtra(EXTRA_THREAD_NAME);
String extraMessage = intent.getStringExtra(EXTRA_EXTRA_MESSAGE);
List<NameValuePair> params = new ArrayList<NameValuePair>();
addNameValuePair(params, fieldsToSend, "exStackTrace", stacktrace);
addNameValuePair(params, fieldsToSend, "exClass", exception);
addNameValuePair(params, fieldsToSend, "exDateTime", dateTime);
addNameValuePair(params, fieldsToSend, "exMessage", message);
addNameValuePair(params, fieldsToSend, "exThreadName", threadName);
if (extraMessage != null)
addNameValuePair(params, fieldsToSend, "extraMessage", extraMessage);
if (availableMemory >= 0)
addNameValuePair(params, fieldsToSend, "devAvailableMemory", availableMemory + "");
if (totalMemory >= 0)
addNameValuePair(params, fieldsToSend, "devTotalMemory", totalMemory + "");
PackageManager pm = getPackageManager();
try {
PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), 0);
addNameValuePair(params, fieldsToSend, "appVersionCode", packageInfo.versionCode + "");
addNameValuePair(params, fieldsToSend, "appVersionName", packageInfo.versionName);
addNameValuePair(params, fieldsToSend, "appPackageName", packageInfo.packageName);
} catch (NameNotFoundException e) {
}
addNameValuePair(params, fieldsToSend, "devModel", android.os.Build.MODEL);
addNameValuePair(params, fieldsToSend, "devSdk", android.os.Build.VERSION.SDK);
addNameValuePair(params, fieldsToSend, "devReleaseVersion", android.os.Build.VERSION.RELEASE);
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(server.toString());
post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
Log.d(TAG, "Created post request");
try {
httpClient.execute(post);
Log.v(TAG, "Reported error: " + intent.toString());
} catch (ClientProtocolException e) {
// Ignore this kind of error
Log.e(TAG, "Error while sending an error report", e);
} catch (SSLException e) {
Log.e(TAG, "Error while sending an error report", e);
} catch (IOException e) {
if (e instanceof SocketException && e.getMessage().contains("Permission denied")) {
Log.e(TAG, "You don't have internet permission", e);
} else {
int maximumRetryCount = getMaximumRetryCount();
int maximumExponent = getMaximumBackoffExponent();
// Retry at a later point in time
AlarmManager alarmMgr = (AlarmManager) getSystemService(ALARM_SERVICE);
int exponent = intent.getIntExtra(EXTRA_CURRENT_RETRY_COUNT, 0);
intent.putExtra(EXTRA_CURRENT_RETRY_COUNT, exponent + 1);
PendingIntent operation = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
if (exponent >= maximumRetryCount) {
// Discard error
Log.w(TAG, "Error report reached the maximum retry count and will be discarded.\nStacktrace:\n" + stacktrace);
return;
}
if (exponent > maximumExponent) {
exponent = maximumExponent;
}
// backoff in ms
long backoff = (1 << exponent) * 1000;
alarmMgr.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + backoff, operation);
}
}
}
use of org.apache.http.NameValuePair in project google-analytics-java by brsanthu.
the class GoogleAnalyticsThreadFactory method post.
@SuppressWarnings({ "rawtypes" })
public GoogleAnalyticsResponse post(GoogleAnalyticsRequest request) {
GoogleAnalyticsResponse response = new GoogleAnalyticsResponse();
if (!config.isEnabled()) {
return response;
}
CloseableHttpResponse httpResponse = null;
try {
List<NameValuePair> postParms = new ArrayList<NameValuePair>();
logger.debug("Processing " + request);
//Process the parameters
processParameters(request, postParms);
//Process custom dimensions
processCustomDimensionParameters(request, postParms);
//Process custom metrics
processCustomMetricParameters(request, postParms);
logger.debug("Processed all parameters and sending the request " + postParms);
HttpPost httpPost = new HttpPost(config.getUrl());
httpPost.setEntity(new UrlEncodedFormEntity(postParms, UTF8));
httpResponse = (CloseableHttpResponse) httpClient.execute(httpPost);
response.setStatusCode(httpResponse.getStatusLine().getStatusCode());
response.setPostedParms(postParms);
EntityUtils.consumeQuietly(httpResponse.getEntity());
if (config.isGatherStats()) {
gatherStats(request);
}
} catch (Exception e) {
if (e instanceof UnknownHostException) {
logger.warn("Coudln't connect to Google Analytics. Internet may not be available. " + e.toString());
} else {
logger.warn("Exception while sending the Google Analytics tracker request " + request, e);
}
} finally {
try {
httpResponse.close();
} catch (Exception e2) {
//ignore
}
}
return response;
}
use of org.apache.http.NameValuePair in project androidquery by androidquery.
the class AQueryAsyncTest method testAjaxPostRaw.
public void testAjaxPostRaw() throws UnsupportedEncodingException {
String url = "http://www.androidquery.com/p/doNothing";
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("q", "androidquery"));
HttpEntity entity = new UrlEncodedFormEntity(pairs, "UTF-8");
Map<String, Object> params = new HashMap<String, Object>();
params.put(AQuery.POST_ENTITY, entity);
aq.ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject jo, AjaxStatus status) {
done(url, jo, status);
}
});
waitAsync();
JSONObject jo = (JSONObject) result;
assertNotNull(jo);
assertNotNull(jo.opt("params"));
assertEquals("POST", jo.optString("method"));
}
use of org.apache.http.NameValuePair in project androidquery by androidquery.
the class AjaxLoadingActivity method async_post_entity.
/*
public void async_post2(){
String url = "your url";
//get your byte array or file
byte[] data = new byte[1000];
Map<String, Object> params = new HashMap<String, Object>();
//put your post params
params.put("paramName", data);
AjaxCallback<byte[]> cb = new AjaxCallback<byte[]>() {
@Override
public void callback(String url, byte[] data, AjaxStatus status) {
System.out.println(data);
System.out.println(status.getCode() + ":" + status.getError());
}
};
cb.url(url).type(byte[].class);
//set Content-Length header
cb.params(params).header("Content-Length", Integer.toString(data.length));
cb.async(this);
}
*/
public void async_post_entity() throws UnsupportedEncodingException {
String url = "http://search.twitter.com/search.json";
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("q", "androidquery"));
HttpEntity entity = new UrlEncodedFormEntity(pairs, "UTF-8");
Map<String, Object> params = new HashMap<String, Object>();
params.put(AQuery.POST_ENTITY, entity);
aq.progress(R.id.progress).ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject json, AjaxStatus status) {
showResult(json, status);
}
});
}
use of org.apache.http.NameValuePair in project android-instagram by markchang.
the class ImageListActivity method postComment.
public void postComment(String comment, InstagramImage image, String username) {
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new BasicNameValuePair("comment_text", comment));
String jsonResponse = Utils.doRestulPut(httpClient, Utils.createCommentUrl(image.pk), postParams, this);
if (jsonResponse != null) {
image.comment_list.add(new Comment(username, comment));
Toast.makeText(this, "Comment successful", Toast.LENGTH_SHORT).show();
adapter.notifyDataSetChanged();
} else {
Toast.makeText(this, "Comment failed", Toast.LENGTH_SHORT).show();
}
}
Aggregations