org.acra
Class ErrorReporter

java.lang.Object
  extended by org.acra.ErrorReporter
All Implemented Interfaces:
Thread.UncaughtExceptionHandler

public class ErrorReporter
extends Object
implements Thread.UncaughtExceptionHandler

The ErrorReporter is a Singleton object in charge of collecting crash context data and sending crash reports. It registers itself as the Application's Thread default Thread.UncaughtExceptionHandler.

When a crash occurs, it collects data of the crash context (device, system, stack trace...) and writes a report file in the application private directory. This report file is then sent :

If an error occurs while sending a report, it is kept for later attempts.


Method Summary
 void addCustomData(String key, String value)
          Deprecated. 
 void addReportSender(ReportSender sender)
          Add a ReportSender to the list of active ReportSenders.
 void checkReportsOnApplicationStart()
          This method looks for pending reports and does the action required depending on the interaction mode set.
 String getCustomData(String key)
          Gets the current value for a key in your reports custom data field.
static ErrorReporter getInstance()
          Deprecated. since 4.3.0 Use ACRA.getErrorReporter() instead.
 void handleException(Throwable e)
          Send a report for a Throwable with the reporting interaction mode configured by the developer, the application is then killed and restarted by the system.
 void handleException(Throwable e, boolean endApplication)
          Send a report for a Throwable with the reporting interaction mode configured by the developer.
 void handleSilentException(Throwable e)
          Send a report for this Throwable silently (forces the use of ReportingInteractionMode.SILENT for this report, whatever is the mode set for the application.
 String putCustomData(String key, String value)
           Use this method to provide the ErrorReporter with data of your running application.
 void removeAllReportSenders()
          Clears the list of active ReportSenders.
 String removeCustomData(String key)
          Removes a key/value pair from your reports custom data field.
 void removeReportSender(ReportSender sender)
          Remove a specific instance of ReportSender from the list of active ReportSenders.
 void removeReportSenders(Class<?> senderClass)
          Remove all ReportSender instances from a specific class.
 void setDefaultReportSenders()
          Sets relevant ReportSenders to the ErrorReporter, replacing any previously set ReportSender.
 void setEnabled(boolean enabled)
          Enable or disable this ErrorReporter.
 void setReportSender(ReportSender sender)
          Removes all previously set ReportSenders and set the given one as the new ReportSender.
 void uncaughtException(Thread t, Throwable e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ErrorReporter getInstance()
Deprecated. since 4.3.0 Use ACRA.getErrorReporter() instead.

Returns:
the current instance of ErrorReporter.
Throws:
IllegalStateException - if ACRA.init(android.app.Application) has not yet been called.

addCustomData

@Deprecated
public void addCustomData(String key,
                                     String value)
Deprecated. 

Deprecated. Use putCustomData(String, String).

Parameters:
key - A key for your custom data.
value - The value associated to your key.

putCustomData

public String putCustomData(String key,
                            String value)

Use this method to provide the ErrorReporter with data of your running application. You should call this at several key places in your code the same way as you would output important debug data in a log file. Only the latest value is kept for each key (no history of the values is sent in the report).

The key/value pairs will be stored in the GoogleDoc spreadsheet in the "custom" column, as a text containing a 'key = value' pair on each line.

Parameters:
key - A key for your custom data.
value - The value associated to your key.
Returns:
The previous value for this key if there was one, or null.
See Also:
removeCustomData(String), getCustomData(String)

removeCustomData

public String removeCustomData(String key)
Removes a key/value pair from your reports custom data field.

Parameters:
key - The key of the data to be removed.
Returns:
The value for this key before removal.
See Also:
putCustomData(String, String), getCustomData(String)

getCustomData

public String getCustomData(String key)
Gets the current value for a key in your reports custom data field.

Parameters:
key - The key of the data to be retrieved.
Returns:
The value for this key.
See Also:
putCustomData(String, String), removeCustomData(String)

addReportSender

public void addReportSender(ReportSender sender)
Add a ReportSender to the list of active ReportSenders.

Parameters:
sender - The ReportSender to be added.

removeReportSender

public void removeReportSender(ReportSender sender)
Remove a specific instance of ReportSender from the list of active ReportSenders.

Parameters:
sender - The ReportSender instance to be removed.

removeReportSenders

public void removeReportSenders(Class<?> senderClass)
Remove all ReportSender instances from a specific class.

Parameters:
senderClass - ReportSender class whose instances should be removed.

removeAllReportSenders

public void removeAllReportSenders()
Clears the list of active ReportSenders. You should then call addReportSender(ReportSender) or ACRA will not send any report anymore.


setReportSender

public void setReportSender(ReportSender sender)
Removes all previously set ReportSenders and set the given one as the new ReportSender.

Parameters:
sender - ReportSender to set as the sole sender for this ErrorReporter.

uncaughtException

public void uncaughtException(Thread t,
                              Throwable e)
Specified by:
uncaughtException in interface Thread.UncaughtExceptionHandler

handleSilentException

public void handleSilentException(Throwable e)
Send a report for this Throwable silently (forces the use of ReportingInteractionMode.SILENT for this report, whatever is the mode set for the application. Very useful for tracking difficult defects.

Parameters:
e - The Throwable to be reported. If null the report will contain a new Exception("Report requested by developer").

setEnabled

public void setEnabled(boolean enabled)
Enable or disable this ErrorReporter. By default it is enabled.

Parameters:
enabled - Whether this ErrorReporter should capture Exceptions and forward them as crash reports.

checkReportsOnApplicationStart

public void checkReportsOnApplicationStart()
This method looks for pending reports and does the action required depending on the interaction mode set.


handleException

public void handleException(Throwable e,
                            boolean endApplication)
Send a report for a Throwable with the reporting interaction mode configured by the developer.

Parameters:
e - The Throwable to be reported. If null the report will contain a new Exception("Report requested by developer").
endApplication - Set this to true if you want the application to be ended after sending the report.

handleException

public void handleException(Throwable e)
Send a report for a Throwable with the reporting interaction mode configured by the developer, the application is then killed and restarted by the system.

Parameters:
e - The Throwable to be reported. If null the report will contain a new Exception("Report requested by developer").

setDefaultReportSenders

public void setDefaultReportSenders()
Sets relevant ReportSenders to the ErrorReporter, replacing any previously set ReportSender.



Copyright © 2010-2013. All Rights Reserved.