ACRA 崩溃报告,将崩溃发送到多个电子邮件

ACRA crash report, send crash to multiple emails

我想将我的应用程序的 CrashReport 发送给多个收件人,这是否可能 无需 添加 ErrorReporter,就在 [=13] =]? 如果没有,可能的解决方案是什么?

代码:

import org.acra.ACRA;
import org.acra.ReportingInteractionMode;
import org.acra.annotation.ReportsCrashes;

@ReportsCrashes(
    mailTo = "******@gmail.com",
    mode = ReportingInteractionMode.TOAST,
    resToastText = R.string.crash_toast_text
)

提前致谢。 :)

您必须实现自己的发件人,如下所示:

public class YourOwnSender implements ReportSender {

  private String emails[];
  private Context context;

  public YourOwnSender(Context context, String[] additionalEmails){
    this.email = additionalEmails;
    this.context = context;
  }

  @Override
  public void send(CrashReportData report) throws ReportSenderException {
    StringBuilder log = new StringBuilder();

    log.append("Package: " + report.get(ReportField.PACKAGE_NAME) + "\n");
    log.append("Version: " + report.get(ReportField.APP_VERSION_CODE) + "\n");
    log.append("Android: " + report.get(ReportField.ANDROID_VERSION) + "\n");
    log.append("Manufacturer: " + android.os.Build.MANUFACTURER + "\n");
    log.append("Model: " + report.get(ReportField.PHONE_MODEL) + "\n");
    log.append("Date: " + now + "\n");
    log.append("\n");
    log.append(report.get(ReportField.STACK_TRACE));

    String body = log.toString();
    String subject = mContext.getPackageName() + " Crash Report";

    for(int i=0; i<emails.length; i++) {
      final Intent emailIntent = new Intent(android.content.Intent.ACTION_SENDTO);
    emailIntent.setData(Uri.fromParts("mailto", ACRAgetConfig().mailTo(), null));
    emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
    emailIntent.putExtra(android.content.Intent.EXTRA_BCC, emails);
    mContext.startActivity(emailIntent);
    }
  }
}

您问题的措辞表明您希望发送给多个电子邮件收件人。如果是这种情况,那么只需在 mailTo 属性中用逗号分隔它们。即:

@ReportsCrashes(
    mailTo = "******@gmail.com, someOne@another.address",
    mode = ReportingInteractionMode.TOAST,
    resToastText = R.string.crash_toast_text
)

您不需要为该用例配置另一个 ReportSender