Android 如何在ACRA自定义发件人中获取异常或可丢弃
您好,我需要向Airbrake发送碰撞报告,但我相信ACRA是android平台上用于此目的的更强大的工具,因此我一直在尝试将两者结合起来,并为ACRA实现我自己的Android 如何在ACRA自定义发件人中获取异常或可丢弃,android,acra,Android,Acra,您好,我需要向Airbrake发送碰撞报告,但我相信ACRA是android平台上用于此目的的更强大的工具,因此我一直在尝试将两者结合起来,并为ACRA实现我自己的ReposrtSender,它可以Airbrakenotifyer.notify()。不幸的是,它需要一个异常作为参数,但是send()方法只提供CrashReportData public interface ReportSender { /** * Send crash report data. You don'
ReposrtSender
,它可以Airbrakenotifyer.notify()代码>。不幸的是,它需要一个异常作为参数,但是send()
方法只提供CrashReportData
public interface ReportSender {
/**
* Send crash report data. You don't have to take care of managing Threads,
* just implement what is necessary to handle the data. ACRA will use a
* specific Thread (not the UI Thread) to run your sender.
*
* @param errorContent
* Stores key/value pairs for each report field. A report field
* is identified by a {@link ReportField} enum value.
* @throws ReportSenderException
* If anything goes fatally wrong during the handling of crash
* data, you can (should) throw a {@link ReportSenderException}
* with a custom message.
*/
public void send(CrashReportData errorContent) throws ReportSenderException;
}
以下是我的sender实现,它应该向Airbrake发送报告:
public class MyReportSender implements ReportSender {
public void send(CrashReportData errorContent) throws ReportSenderException {
AirbrakeNotifier.notify(/*Exception is required here*/);
// But only key/value pairs are available here in errorContent param.
}
}
我注意到我可以用CrashReporData
中的一些数据构造一个新的异常,但是如果可能的话,最好得到原始异常。将ACRA jar文件放在项目的libs目录中,并创建CrashReport.java文件
@ReportsCrashes(formUri = "http://www.bugsense.com/api/acra?api_key=6f3855c9", formKey="")
//api_key you will get once you register your application with ACRA.
public class CrashReport extends Application {
@Override
public void onCreate() {
super.onCreate();
// The following line Application register with ACRA
ACRA.init(this);
}
}
在menifest.xml文件中的应用程序标记中设置崩溃报告类,如下所示
android:name="com.example.mydoc.CrashReport"
这里com.example.mydoc是您的崩溃报告所在的应用程序包。虽然这个问题很老,但我仍然想回答它,因为我是通过谷歌找到的,其他人可能也会这样做
无法在ReportSender
中获取异常。您可以获取它的stacktrace,但不能获取对象本身(因为它位于与发送者不同的进程中,并且此时可能已经被垃圾收集)
如果需要对象,可以使用ReportPrimer
。它在生成报告之前被调用,因此可以访问ReportBuilder
,它携带异常
对象(以及其他数据,例如崩溃的线程
)。异常在哪里?这是您可以向ACRA注册项目以收集异常信息的方法。若你们想在任何类中出现异常,你们可以在整型中解析空值,它将通过acraun上的异常进行解析,幸运的是,它对我并没有任何帮助。问题是关于自定义发件人中的异常,而不是关于在项目中注册ACRA。谢谢你的尝试。如果你想知道你的例外ACRA是最好的解决方案,但我希望它是免费的一个月