使用ACRA当空崩溃文件(empty crash file when using ACRA)

2019-10-20 17:07发布

我使用下面的代码来生成一个崩溃的文件,该文件是在parse.com创建的,但它是空的。 任何想法,为什么?

另一个问题是,“ACRA.DEFAULT_REPORT_FIELDS;” 有一个错误,默认报表字段不可用。

public class LocalSender implements ReportSender {  
      private final Map<ReportField, String> mMapping = new HashMap<ReportField, String>() ;  
      private FileOutputStream crashReport = null;  
      private Context ctx;  
      public LocalSender(Context ct) {  
           ctx = ct;  
      }  
      public void send(CrashReportData report) throws ReportSenderException {  
           final Map<String, String> finalReport = remap(report);  
           ByteArrayOutputStream buf = new ByteArrayOutputStream();  
           Log.i("hcsh","Report send");  
           try {  
                Set set = finalReport.entrySet();  
                Iterator i = set.iterator();  
                String tmp;  
                while (i.hasNext()) {  
                     Map.Entry<String,String> me = (Map.Entry) i.next();  
                     tmp = "[" + me.getKey() + "]=" + me.getValue();  
                     buf.write(tmp.getBytes());  
                }  
                ParseFile myFile = new ParseFile("crash.txt", buf.toByteArray());  
                myFile.save();  
                ParseObject jobApplication = new ParseObject("AppCrash");  
                jobApplication.put("MyCrash", "app name");  
                jobApplication.put("applicantResumeFile", myFile);  
                try {  
                     jobApplication.save();  
                } catch (ParseException e) {  
                     // TODO Auto-generated catch block  
                     e.printStackTrace();  
                }  
           }catch (FileNotFoundException e) {  
                Log.e("TAG", "IO ERROR",e);  
           }  
           catch (IOException e) {  
                Log.e("TAG", "IO ERROR",e);  
           } catch (ParseException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
           }  
 }  
 private Map<String, String> remap(Map<ReportField, String> report) {  
      ReportField[] fields = ACRA.getConfig().customReportContent();  
      if (fields.length == 0) {  
           fields = ACRA.DEFAULT_REPORT_FIELDS;
         }  
      final Map<String, String> finalReport = new HashMap<String, String>(  
                report.size());  
      for (ReportField field : fields) {  
           if (mMapping == null || mMapping.get(field) == null) {  
                finalReport.put(field.toString(), report.get(field));  
           } else {  
                finalReport.put(mMapping.get(field), report.get(field));  
           }  
      }  
      return finalReport;  
 }

 } 

Answer 1:

目前是没有这样的不变ACRA.DEFAULT_REPORT_FIELDS 。 您正在寻找ACRAConstants.DEFAULT_REPORT_FIELDS



Answer 2:

ACRA.DEFAULT_REPORT_FIELDS恒定值是在ACRA-4.3.0版本...

如果你正在使用ACRA-4.5.0版本ACRA你会得到这个错误“DEFAULT_REPORT_FIELDS不能得到解决或不是场”。

尝试使用ACRA-4.5.0版本,然后使用下面的代码

//提取所需的数据从崩溃报告。

String reportBody = createCrashReport(report);

/ **提取所需的数据从崩溃报告。 * /

private String createCrashReport(CrashReportData report) {

    // I've extracted only basic information.
    // U can add loads more data using the enum ReportField. See below.
    StringBuilder body = new StringBuilder();
    body.append(
            "Device : " + report.getProperty(ReportField.BRAND) + "-"
                    + report.getProperty(ReportField.PHONE_MODEL))
            .append("\n")
            .append("Android Version :"
                    + report.getProperty(ReportField.ANDROID_VERSION))
            .append("\n")
            .append("App Version : "
                    + report.getProperty(ReportField.APP_VERSION_CODE))
            .append("\n")
            .append("STACK TRACE : \n"
                    + report.getProperty(ReportField.STACK_TRACE));

    return body.toString();
}

不要使用下面的代码////////////////////////

最终字符串reportBody = buildBody(为arg0);

私人字符串buildBody(CrashReportData errorContent){

    ReportField[] fields = ACRA.getConfig().customReportContent();
    if (fields.length == 0) {
        // fields = ACRA.DEFAULT_MAIL_REPORT_FIELDS;
        fields = ACRA.DEFAULT_REPORT_FIELDS;
    }

    final StringBuilder builder = new StringBuilder();
    for (ReportField field : fields) {
        builder.append(field.toString()).append("=");
        builder.append(errorContent.get(field));
        builder.append('\n');
    }
    return builder.toString();
}

快乐编码....



文章来源: empty crash file when using ACRA
标签: android acra