public class HttpSender extends Object implements ReportSender
The ReportSender
used by ACRA when ReportsCrashes.formUri()
has been defined in order to post crash data to a custom server-side data
collection script. It sends all data in a POST request with parameters named
with easy to understand names (basically a string conversion of
ReportField
enum values) or based on your own conversion Map from
ReportField
values to String.
To use specific POST parameter names, you can provide your own report fields mapping scheme:
@ReportsCrashes(...) public class myApplication extends Application { public void onCreate() { super.onCreate(); ACRA.init(this); Map<ReportField, String> mapping = new HashMap<ReportField, String>(); mapping.put(ReportField.APP_VERSION_CODE, "myAppVerCode'); mapping.put(ReportField.APP_VERSION_NAME, "myAppVerName'); //... mapping.put(ReportField.USER_EMAIL, "userEmail'); // remove any default report sender ErrorReporter.getInstance().removeAllReportSenders(); // create your own instance with your specific mapping ErrorReporter.getInstance().addReportSender(new ReportSender("http://my.domain.com/reports/receiver.py", mapping)); } }
Modifier and Type | Class and Description |
---|---|
static class |
HttpSender.Method
Available HTTP methods to send data.
|
static class |
HttpSender.Type
Type of report data encoding, currently supports Html Form encoding and
JSON.
|
Constructor and Description |
---|
HttpSender(HttpSender.Method method,
HttpSender.Type type,
Map<ReportField,String> mapping)
Create a new HttpSender instance with its destination taken from
ACRA.getConfig() dynamically. |
HttpSender(HttpSender.Method method,
HttpSender.Type type,
String formUri,
Map<ReportField,String> mapping)
Create a new HttpPostSender instance with a fixed destination provided as
a parameter.
|
Modifier and Type | Method and Description |
---|---|
void |
send(android.content.Context context,
CrashReportData report)
Send crash report data.
|
void |
setBasicAuth(String username,
String password)
Set credentials for this HttpSender that override (if present) the ones
set globally.
|
public HttpSender(HttpSender.Method method, HttpSender.Type type, Map<ReportField,String> mapping)
Create a new HttpSender instance with its destination taken from
ACRA.getConfig()
dynamically. Configuration changes to the
formUri are applied automatically.
method
- HTTP HttpSender.Method
to be used to send data. Currently only
HttpSender.Method.POST
and HttpSender.Method.PUT
are available. If
HttpSender.Method.PUT
is used, the ReportField.REPORT_ID
is appended to the formUri to be compliant with RESTful APIs.type
- HttpSender.Type
of encoding used to send the report body.
HttpSender.Type.FORM
is a simple Key/Value pairs list as defined
by the application/x-www-form-urlencoded mime type.mapping
- Applies only to HttpSender.Method.POST
method parameter. If null,
POST parameters will be named with ReportField
values
converted to String with .toString(). If not null, POST
parameters will be named with the result of
mapping.get(ReportField.SOME_FIELD);public HttpSender(HttpSender.Method method, HttpSender.Type type, String formUri, Map<ReportField,String> mapping)
Create a new HttpPostSender instance with a fixed destination provided as a parameter. Configuration changes to the formUri are not applied.
method
- HTTP HttpSender.Method
to be used to send data. Currently only
HttpSender.Method.POST
and HttpSender.Method.PUT
are available. If
HttpSender.Method.PUT
is used, the ReportField.REPORT_ID
is appended to the formUri to be compliant with RESTful APIs.type
- HttpSender.Type
of encoding used to send the report body.
HttpSender.Type.FORM
is a simple Key/Value pairs list as defined
by the application/x-www-form-urlencoded mime type.formUri
- The URL of your server-side crash report collection script.mapping
- Applies only to HttpSender.Method.POST
method parameter. If null,
POST parameters will be named with ReportField
values
converted to String with .toString(). If not null, POST
parameters will be named with the result of
mapping.get(ReportField.SOME_FIELD);public void setBasicAuth(String username, String password)
Set credentials for this HttpSender that override (if present) the ones set globally.
username
- The username to set for HTTP Basic Auth.password
- The password to set for HTTP Basic Auth.public void send(android.content.Context context, CrashReportData report) throws ReportSenderException
ReportSender
send
in interface ReportSender
context
- Android Context in which to send the crash report.report
- Stores key/value pairs for each report field. A report field
is identified by a ReportField
enum value.ReportSenderException
- If anything goes fatally wrong during the handling of crash
data, you can (should) throw a ReportSenderException
with a custom message.Copyright © 2010-2015. All Rights Reserved.