【问题标题】:Emailing Reports using ACRA(ver 5.7.0) on Android not working在 Android 上使用 ACRA(版本 5.7.0)通过电子邮件发送报告不起作用
【发布时间】:2020-09-01 16:35:58
【问题描述】:

我正在尝试捕获崩溃日志并使用 ACRA 通过邮件发送。但是没有收到邮件。

我做了以下事情:

1.在主Activity的oncreate方法中初始化ACRA

ACRA.init(getApplication()); 

2。指定报告内容

@AcraCore(reportContent = {
        ReportField.REPORT_ID,
        ReportField.USER_APP_START_DATE,
        ReportField.USER_CRASH_DATE,
        ReportField.APP_VERSION_CODE,
        ReportField.APP_VERSION_NAME,
        ReportField.ANDROID_VERSION,
        ReportField.DEVICE_ID,
        ReportField.BRAND,
        ReportField.BUILD,
        ReportField.DEVICE_FEATURES,
        ReportField.PACKAGE_NAME,
        ReportField.REPORT_ID,
        ReportField.STACK_TRACE,
        ReportField.APPLICATION_LOG,
        ReportField.LOGCAT,
        ReportField.USER_EMAIL
},
        reportFormat = JSON,
        reportSenderFactoryClasses = {MainActivity.ACRASenderFactory.class}

)

3.下面是 Acrareportsender 类

public class ACRAReportSender implements ReportSender {
    public ACRAReportSender(){
        Log.e("ACRA", "Report Sender created");
    }
    @Override

    public void send(Context context, CrashReportData crashReportData) throws ReportSenderException {
        Log.e("ACRA", "Before sending crash report");
        String reportBody = createCrashReport(crashReportData);
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setType("vnd.android.cursor.dir/email");
        String mail[] = {"brajesh.poovakkad@gmail.com"};
        emailIntent.putExtra(Intent.EXTRA_EMAIL, mail);
        emailIntent.putExtra(Intent.EXTRA_TEXT, reportBody);
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "ACRA Crash Report");
        context.startActivity(Intent.createChooser(emailIntent, "Send crash to developers by email ..."));
    }
    public String createCrashReport(CrashReportData crashReportData){
        StringBuilder body = new StringBuilder();
        body.append("Device : " + crashReportData.getString(ReportField.BRAND) + " - " + crashReportData.getString(ReportField.PHONE_MODEL))
                .append("\n")
                .append("Android Version : " + crashReportData.getString(ReportField.ANDROID_VERSION))
                .append("\n")
                .append("App Version : " + crashReportData.getString(ReportField.APP_VERSION_CODE))
                .append("\n")
                .append("STACK TRACE : \n" + crashReportData.getString(ReportField.STACK_TRACE));
        return body.toString();

    }
}

4. AcraSenderFactory 类

public class ACRASenderFactory implements ReportSenderFactory {
    public ACRASenderFactory(){
        Log.e("ACRA", "Creating Sender Factory");
    }

    @NonNull
    public ReportSender create(Context context, CoreConfiguration acraConfiguration) {
        Log.e("ACRA", "Returning Report Sender");
        return new ACRAReportSender();
    }
}

从 logcat 验证的输出(如下提供)

1. 09-01 20:36:06.063  3938  3938 I ACRA    : ACRA is enabled for com.example.myapplication, initializing..    

2. ACRA    : ACRA caught a RuntimeException for com.example.myapplication     

3. 09-01 20:36:06.529  3938  3938 D ACRA    : Building report
09-01 20:36:06.535  3938  4022 D ACRA    : Calling collector org.acra.collector.LogCatCollector
09-01 20:36:06.536  3938  4020 D ACRA    : Calling collector org.acra.collector.DropBoxCollector
09-01 20:36:06.536  3938  4020 D ACRA    : Collector org.acra.collector.DropBoxCollector completed
09-01 20:36:06.536  3938  4020 D ACRA    : Calling collector org.acra.collector.ReflectionCollecto..................
.......................

....................
ACRA    : ServicePluginLoader loading services from ServiceLoader : java.util.ServiceLoader[org.acra.sender.ReportSenderFactory].......
...........................................
...........................................
09-01 20:36:06.586  3938  4010 D ACRA    : Ignoring disabled ReportSenderFactory of type EmailIntentSenderFactory
09-01 20:36:06.586  3938  4010 D ACRA    : reportSenderFactories : []

.................................................. ..................................... ..................................................... …………

09-01 20:36:06.590  3938  4010 D ACRA    : Checking plugin Configuration : org.acra.config.SchedulerConfiguration@1d3f9ef against plugin class : class org.acra.config.HttpSenderConfiguration
09-01 20:36:06.590  3938  4010 D ACRA    : Checking plugin Configuration : org.acra.config.HttpSenderConfiguration@b426cfc against plugin class : class org.acra.config.HttpSenderConfiguration
**09-01 20:36:06.591  3938  4010 D ACRA    : Ignoring disabled ReportSenderFactory of type HttpSenderFactory**

..............................................................
.............................................................
.............................................................
09-01 20:36:06.616  3938  3938 D ACRA    : Ignoring disabled ReportInteraction of type NotificationInteraction
09-01 20:36:06.616  3938  3938 D ACRA    : Mark 2020-09-01T20:36:06.565+05:30.stacktrace as approved.
09-01 20:36:06.617  3938  3938 D ACRA    : Schedule report sending
09-01 20:36:06.626  3938  3938 D ACRA    : config#reportSenderFactoryClasses : ImmutableList{[]}
09-01 20:36:06.626  3938  3938 D ACRA    : Using PluginLoader to find ReportSender factories

上面的日志说

a. Acra is getting initialized
b. acra is catching crash
c. report is approved

查询:

  **1. Where am i going wrong. why is it not sending mail**
  2. Is this, **"Ignoring disabled ReportSenderFactory of type HttpSenderFactory"**, as seen from the logs, the reason for not receiving reports via mail? If yes, how this can be rectified ?

注意:在清单文件中,提供了 Internet 权限

【问题讨论】:

    标签: acra


    【解决方案1】:

    您的ReportSenderFactory 不能是内部类。要么使其成为顶级类,要么将其声明为静态。它也不能是抽象的。

    【讨论】:

    • 我已将 ReportsenderFactory 移至顶级类并删除了静态。报告仍然没有收到我的邮件。我在主活动类中初始化 ACRA ( ACRA.init ),在两个不同的文件中有 reportsender 和 senderfactory 类。我的问题是,当我初始化 ACRA 时,它是否在与应用程序主线程不同的线程中单独运行并监视应用程序线程是否有任何异常并在发生时捕获它们并发送报告?还是需要在主活动类中专门调用
    • 谢谢...它工作...我错过了一些基本的设置点
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-08
    • 1970-01-01
    • 2021-10-02
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多