在安卓系统上使用ACRA(5.7.0版)发送电子邮件报告不起作用



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

我做了以下工作:

1.在主活动的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.AcraSender工厂级

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 ?

注意:在清单文件中,提供互联网权限

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

相关内容

  • 没有找到相关文章

最新更新