Hi Habrodroids!
If your application crashes in production and you need to quickly understand why, on which device, with which firmware and configuration, then this little topic will tell you about one way to solve this problem.
Under a cat the description of opportunities of ACRA.
The standard message about the fall of the application does not help much (a banal grid), no useful information about the device or its configuration, but ACRA comes to the rescue -
code.google.com/p/acraThis library helps to make reports on application crashes informative and more convenient way.
The following methods are available out of the box:
1. Write a crash report to your Google Docs document (default method)
2. Sending report to mail
3. Sending data to a server where your script can process it arbitrarily
You can also quite simply write your ReportSender by implementing the send method of this interface.
There are several modes of reporting notifications:
1. Silent (by default) - a report is written to your Google document without informing the user about it and the standard drop dialog is called
2. Toast - a toast notification appears with your message
3. Notification - a message will appear in the status bar and then a dialogue in which you can enter a comment (optional).
I note that quite a few parameters are sent to the report, but they can be selected by setting the customReportContent parameter in the annotation.
Installation')
Download the zip-archive from the link above. Next, throw the jar library into the libs project folder, add the link to the Build Path in Eclipse and it's ready to use.
Work exampleAfter getting acquainted with all the ways of sending the report, I stopped at the first one (sending it to Google Docs).
Further I will tell how to make this miracle work (also, it is described in the project wiki).
First of all, we need an instance of the Application class for which we will add an annotation and a couple of lines of code, like this:
import org.acra.*; import org.acra.annotation.*; @ReportsCrashes( formKey = " ", logcatArguments = { "-t", "50", Constants.DEBUG_TAG+":D"} ) public class MyApp extends Application { @Override public void onCreate() { ACRA.init(this); ErrorReporter.getInstance().checkReportsOnApplicationStart(); super.onCreate(); } }
And you need to add a description of the name of the Application object to your manifest:
<application android:name="MyApp" ...
In the annotation, we indicate the key of the form (how and where to get it will be described below) and the output filtering parameters LogCat. In the report In the filter parameter, we limit the number of log entries to 50 pieces and prompt the library to include our custom tag in the report (to be honest, this filter is odd, but adds all the necessary tags).
By the way, do not forget to add permission to read logs in the manifest:
<uses-permission android:name="android.permission.READ_LOGS"/> </pre>
Next, in the onCreate method, we initialize the library and tell it to check early reports when the application starts. This convenient option allows you to upload reports to you in a document that were recorded earlier, but were not sent (for example, there was no Internet on the device).
Preparing Google DocsYou probably have a Google account. Enter Google Docs and click the “Load” button and select the file CrashReports-Template.csv in the ACRA archive in the doc folder. After loading, we can rename the dock, it does not matter. Go to the document in the Tools menu, select Form-> Create Form. A new window will open in which you need to uncheck the “Require <your domain> sign-in to view this form” box. At the bottom of this window in the link will be the key you need - formKey, save it. Click the “save” button at the top of this window and your document is ready to receive bug reports. Insert the saved key into the code and everything is ready!
Many additional examples are available in the wiki library.
code.google.com/p/acra/wiki/AdvancedUsageIn addition, here you can read the discussion of the considered issue and see alternative ways to handle the fall:
stackoverflow.com/questions/601503/how-do-i-obtain-crash-data-from-my-android-applicationI will add that the sent reports instantly appear in the form of your document.
All questions and comments on the topic, as usual, in a personal.