Android uses Acra to send a crashreport

Source: Internet
Author: User
public class MainActivity extends Activity {    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        TextView v= null;        v.setText("abc");    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        getMenuInflater().inflate(R.menu.activity_main, menu);        return true;    }}

Add Acra to Application

@ReportsCrashes(formKey="dGVacG0ydVHnaNHjRjVTUTEtb3FPWGc6MQ",mailTo = "fenghanlu@163.com",mode = ReportingInteractionMode.DIALOG,customReportContent = { ReportField.APP_VERSION_NAME, ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL, ReportField.CUSTOM_DATA,ReportField.BRAND, ReportField.STACK_TRACE, ReportField.LOGCAT,ReportField.USER_COMMENT },resToastText = R.string.crash_toast_text, // optional, displayed as soon as the crash occurs, before collecting data which can take a few secondsresDialogText = R.string.crash_dialog_text,resDialogIcon = android.R.drawable.ic_dialog_info, //optional. default is a warning signresDialogTitle = R.string.crash_dialog_title, // optional. default is your application nameresDialogCommentPrompt = R.string.crash_dialog_comment_prompt, // optional. when defined, adds a user text field input with this text resource as a labelresDialogOkToast = R.string.crash_dialog_ok_toast // optional. displays a Toast message when the user accepts to send a report.)public class TestApplication extends Application{@Overridepublic void onCreate() {super.onCreate();ACRA.init(this);ErrorReporter.getInstance().removeAllReportSenders();ErrorReporter.getInstance().setReportSender(new CrashReportSender(getApplicationContext()));//ErrorReporter.getInstance().setReportSender(new AcraSender(getApplicationContext(),"http://10.32.202.155:9876"));}}

Custom sender

ublic class CrashReportSender implements ReportSender{private final Context mContext;public final static String formUri="http://10.32.202.155:9876";public CrashReportSender(Context mContext) {super();this.mContext = mContext;ACRA.getErrorReporter().putCustomData("PLATFORM", "ANDROID");ACRA.getErrorReporter().putCustomData("BUILD_ID", android.os.Build.ID);ACRA.getErrorReporter().putCustomData("DEVICE_NAME", android.os.Build.PRODUCT);}@Overridepublic void send(CrashReportData arg0) throws ReportSenderException {EmailIntentSender emailSender = new EmailIntentSender(mContext);        emailSender.send(arg0);        // send crash report to host        HttpPostSender httpSender = new HttpPostSender(formUri, null);        httpSender.send(arg0);        //send crash report to google        GoogleFormSender googleSender =new GoogleFormSender();        googleSender.send(arg0);}

Add registration to androidmanifest. xml

   <activity            android:name="org.acra.CrashReportDialog"            android:excludeFromRecents="true"            android:finishOnTaskLaunch="true"            android:launchMode="singleInstance"            android:theme="@android:style/Theme.Dialog" />

Note: The Acra version must be 4.4.0 or later.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.