-
-
Save joemccall86/9b25aeb3d7cf336bf9e9 to your computer and use it in GitHub Desktop.
Custom ReportSender for HockeyApp and ACRA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.hockeyapp.android.demo; | |
public class HockeySender implements ReportSender { | |
public static final String TAG = "HockeySender"; | |
private static String BASE_URL = "https://rink.hockeyapp.net/api/2/apps/"; | |
private static String CRASHES_PATH = "/crashes"; | |
@Override | |
public void send(Context context, CrashReportData errorContent) throws ReportSenderException { | |
final String log = createCrashLog(errorContent); | |
final String url = BASE_URL + context.getString(R.string.hockey_app_id) + CRASHES_PATH; | |
try { | |
URL urlObject = new URL(url); | |
final HttpsURLConnection httpsURLConnection = (HttpsURLConnection) urlObject.openConnection(); | |
final String output = URLEncoder.encode("raw=" + log + | |
"&userID=" + errorContent.get(ReportField.INSTALLATION_ID) + | |
"&contact=" + errorContent.get(ReportField.USER_EMAIL) + | |
"&description=" + errorContent.get(ReportField.USER_COMMENT), | |
"utf-8"); | |
final byte[] outputBytes = output.getBytes(); | |
httpsURLConnection.setDoOutput(true); | |
httpsURLConnection.setFixedLengthStreamingMode(outputBytes.length); | |
try { | |
OutputStream outputStream = new BufferedOutputStream(httpsURLConnection.getOutputStream()); | |
outputStream.write(outputBytes); | |
InputStream in = new BufferedInputStream(httpsURLConnection.getInputStream()); | |
Log.v(TAG, in.toString()); | |
} finally { | |
httpsURLConnection.disconnect(); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
private String createCrashLog(CrashReportData report) { | |
Date now = new Date(); | |
return "Package: " + report.get(ReportField.PACKAGE_NAME) + "\n" + | |
"Version Name: " + report.get(ReportField.APP_VERSION_NAME) + "\n" + | |
"Version Code: " + report.get(ReportField.APP_VERSION_CODE) + "\n" + | |
"Android: " + report.get(ReportField.ANDROID_VERSION) + "\n" + | |
"Manufacturer: " + android.os.Build.MANUFACTURER + "\n" + | |
"Model: " + report.get(ReportField.PHONE_MODEL) + "\n" + | |
"Date: " + now + "\n" + | |
"\n" + | |
report.get(ReportField.STACK_TRACE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment