MyApplication.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package com.guiying.module;
  2. import android.content.Context;
  3. import android.support.multidex.MultiDex;
  4. import com.alibaba.android.arouter.launcher.ARouter;
  5. import com.guiying.module.common.base.BaseApplication;
  6. import com.guiying.module.common.utils.Utils;
  7. import org.acra.ACRA;
  8. import org.acra.ReportField;
  9. import org.acra.ReportingInteractionMode;
  10. import org.acra.annotation.ReportsCrashes;
  11. import org.acra.collector.CrashReportData;
  12. import org.acra.sender.EmailIntentSender;
  13. import org.acra.sender.ReportSender;
  14. import org.acra.sender.ReportSenderException;
  15. /**
  16. * <p>这里仅需做一些初始化的工作</p>
  17. *
  18. * @author 张华洋 2017/2/15 20:14
  19. * @version V1.2.0
  20. * @name MyApplication
  21. */
  22. @ReportsCrashes(
  23. mailTo = "guiying705@Gmail.com",
  24. mode = ReportingInteractionMode.DIALOG,
  25. customReportContent = {
  26. ReportField.APP_VERSION_NAME,
  27. ReportField.ANDROID_VERSION,
  28. ReportField.PHONE_MODEL,
  29. ReportField.CUSTOM_DATA,
  30. ReportField.BRAND,
  31. ReportField.STACK_TRACE,
  32. ReportField.LOGCAT,
  33. ReportField.USER_COMMENT},
  34. resToastText = R.string.crash_toast_text,
  35. resDialogText = R.string.crash_dialog_text,
  36. resDialogTitle = R.string.crash_dialog_title)
  37. public class MyApplication extends BaseApplication {
  38. @Override
  39. public void onCreate() {
  40. super.onCreate();
  41. if (Utils.isAppDebug()) {
  42. //开启InstantRun之后,一定要在ARouter.init之前调用openDebug
  43. ARouter.openDebug();
  44. ARouter.openLog();
  45. }
  46. ARouter.init(this);
  47. //崩溃日志记录初始化
  48. ACRA.init(this);
  49. ACRA.getErrorReporter().removeAllReportSenders();
  50. ACRA.getErrorReporter().setReportSender(new CrashReportSender());
  51. }
  52. @Override
  53. protected void attachBaseContext(Context base) {
  54. super.attachBaseContext(base);
  55. // dex突破65535的限制
  56. MultiDex.install(this);
  57. }
  58. /**
  59. * 发送崩溃日志
  60. */
  61. private class CrashReportSender implements ReportSender {
  62. CrashReportSender() {
  63. ACRA.getErrorReporter().putCustomData("PLATFORM", "ANDROID");
  64. ACRA.getErrorReporter().putCustomData("BUILD_ID", android.os.Build.ID);
  65. ACRA.getErrorReporter().putCustomData("DEVICE_NAME", android.os.Build.PRODUCT);
  66. }
  67. @Override
  68. public void send(Context context, CrashReportData crashReportData) throws ReportSenderException {
  69. EmailIntentSender emailSender = new EmailIntentSender(getApplicationContext());
  70. emailSender.send(context, crashReportData);
  71. }
  72. }
  73. }