【发布时间】:2021-02-26 04:09:35
【问题描述】:
我需要修改发送到 Acrium 的报告,所以我使用 HttpSender。我曾尝试使用 ReportSender 而不是 HttpSender,但结果是一样的:报告没有发送到 Acrarium。使用默认设置(没有 SenderFactory::class)可以正常工作。
这是 MyApplication 类:
@AcraCore(
buildConfigClass = BuildConfig::class,
reportContent = [ReportField.APP_VERSION_NAME, ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL, ReportField.CUSTOM_DATA, ReportField.STACK_TRACE],
reportSenderFactoryClasses = [SenderFactory::class]
)
@AcraHttpSender(
uri = "http://localhost:port/report",
basicAuthLogin = "..........",
basicAuthPassword = "..........,
httpMethod = HttpSender.Method.POST
)
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
ACRA.init(this)
}
}
我的 CustomHttpSender:
class CustomSender(config: CoreConfiguration, method: Method = Method.POST, type: StringFormat? = null)
: HttpSender(config, method, type) {
override fun send(context: Context, report: CrashReportData) {
try {
report.put(
ReportField.PHONE_MODEL,
report.getString(ReportField.PHONE_MODEL) + getAdditionalInfo()
)
println("Report: \n" + report.getString(ReportField.PHONE_MODEL))
// sendHttpRequests(config, context, mMethod, mType.matchingHttpContentType, login, password, httpConfig.connectionTimeout,
// httpConfig.socketTimeout, httpConfig.httpHeaders, reportAsString, reportUrl, uris)
Log.e("YourOwnSender", report.toJSON())
} catch (e: Exception) {
e.printStackTrace()
}
}
override fun sendHttpRequests(configuration: CoreConfiguration, context: Context, method: Method,
contentType: String, login: String?, password: String?, connectionTimeOut: Int, socketTimeOut: Int,
headers: MutableMap<String, String>?, content: String, url: URL, attachments: MutableList<Uri>
) {
}
fun getAdditionalInfo(): String {
return " ABC-001"
}
}
我的发件人工厂:
@AutoService(ReportSenderFactory::class)
class SenderFactory: ReportSenderFactory {
override fun create(context: Context, config: CoreConfiguration): ReportSender {
return CustomSender(config, HttpSender.Method.POST, StringFormat.JSON)
}
override fun enabled(config: CoreConfiguration): Boolean {
return true
}
}
使用默认设置和CustomSender的logcat是一样的:
2021-02-26 10:55:05.163 1448-1448/? I/xample.acrates: Late-enabling -Xcheck:jni
2021-02-26 10:55:05.330 1448-1448/? E/xample.acrates: Unknown bits set in runtime_flags: 0x8000
2021-02-26 10:55:05.628 1448-1448/com.example.acratest I/ACRA: ACRA is enabled for com.example.acratest, initializing...
2021-02-26 10:55:05.774 1448-1448/com.example.acratest E/xample.acrates: Invalid ID 0x00000000.
2021-02-26 10:55:05.853 1448-1448/com.example.acratest W/xample.acrates: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2021-02-26 10:55:05.854 1448-1448/com.example.acratest W/xample.acrates: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2021-02-26 10:55:05.952 1448-1525/com.example.acratest E/xample.acrates: Invalid ID 0x00000000.
2021-02-26 10:55:05.999 1448-1495/com.example.acratest I/Adreno: QUALCOMM build : 4a00b69, I4e7e888065
Build Date : 04/09/19
OpenGL ES Shader Compiler Version: EV031.26.06.00
Local Branch : mybranche95ae4c8-d77f-f18d-a9ef-1458d0b52ae8
Remote Branch : quic/gfx-adreno.lnx.1.0
Remote Branch : NONE
Reconstruct Branch : NOTHING
2021-02-26 10:55:05.999 1448-1495/com.example.acratest I/Adreno: Build Config : S L 8.0.5 AArch64
2021-02-26 10:55:06.003 1448-1495/com.example.acratest I/Adreno: PFP: 0x005ff110, ME: 0x005ff066
2021-02-26 10:55:06.020 1448-1495/com.example.acratest W/Gralloc3: mapper 3.x is not supported
标签运行有区别。
没有 SenderFactory::class 的默认设置:
如何将修改后的报告发送到 Acrarium?
--------------- 编辑 ---------------
我只需要添加一行:
super.send(上下文,报告)
override fun send(context: Context, report: CrashReportData) {
try {
report.put(
ReportField.PHONE_MODEL,
report.getString(ReportField.PHONE_MODEL) + getAdditionalInfo()
)
Log.e("YourOwnSender", report.toJSON())
super.send(context, report)
} catch (e: Exception) {
throw ReportSenderException(
"Error while sending JSON report via Http POST",
e
)
}
}
而且我不需要重写 fun sendHttpRequests。
【问题讨论】:
-
不确定我是否理解您要执行的操作。
ACRA.getErrorReporter().putCustomData("myKey", "myValue");对你来说还不够吗? -
很遗憾,没有。我需要 Acrarium 的“报告”仪表板中的更多信息 - “设备”列,因为我将 ACRA 用于内部应用程序并且所有设备都具有相同的型号。我需要的是在 Acrarium 的“报告”仪表板中添加一个新列,或者修改该列表中显示的当前信息。目的是为了过滤。
-
我认为可行的方法是实现
Collector,如下所述:github.com/ACRA/acra/wiki/Custom-Extensions 虽然没有直接的示例 -
大概是这样的:github.com/ACRA/acra/blob/master/acra-core/src/main/java/org/…通过设置顺序,应该可以覆盖已有的值
-
好的,我试试。谢谢。