【问题标题】:ACRA crash report, send crash to multiple emailsACRA 崩溃报告,将崩溃发送到多个电子邮件
【发布时间】:2015-10-22 19:34:17
【问题描述】:

我想将我的应用程序的CrashReport 发送给多个收件人,这可能添加ErrorReporter,就在@ReportCrashes 中吗? 如果没有,有什么可能的解决方案?

代码:

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
)

提前致谢。 :)

【问题讨论】:

标签: java android crash-reports acra


【解决方案1】:

你必须实现一个自己的发送者,像这样:

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);
    }
  }
}

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-02
      • 2013-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多