Java tutorial
/******************************************************************************* * Gaggle is Copyright 2010 by Geeksville Industries LLC, a California limited liability corporation. * * Gaggle is distributed under a dual license. We've chosen this approach because within Gaggle we've used a number * of components that Geeksville Industries LLC might reuse for commercial products. Gaggle can be distributed under * either of the two licenses listed below. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Commercial Distribution License * If you would like to distribute Gaggle (or portions thereof) under a license other than * the "GNU General Public License, version 2", contact Geeksville Industries. Geeksville Industries reserves * the right to release Gaggle source code under a commercial license of its choice. * * GNU Public License, version 2 * All other distribution of Gaggle must conform to the terms of the GNU Public License, version 2. The full * text of this license is included in the Gaggle source, see assets/manual/gpl-2.0.txt. ******************************************************************************/ package com.geeksville.android; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import android.app.Activity; /** * Report exceptions to the geeksville hub service * * @author kevinh * */ public class GeeksvilleExceptionHandler extends PostMortemReportExceptionHandler { private URI submitURL; public GeeksvilleExceptionHandler(Activity aApp) { super(aApp); try { submitURL = new URI("http://geeksvillehub.appspot.com/crashlog"); } catch (URISyntaxException e) { throw new RuntimeException(e); } } @Override protected void submit(Throwable e) { String theErrReport = getDebugReport(e); try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(submitURL); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("appname", mApp.getPackageName())); nameValuePairs.add(new BasicNameValuePair("content", theErrReport)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); BufferedReader respStream = new BufferedReader(new InputStreamReader(entity.getContent())); // String message = respStream.readLine(); respStream.close(); // Log.d("resp", message); } catch (IOException e1) { // Failure contacting geeksville, ignore it for now (FIXME) } } }