错误日志的收集(ACRA的使用教程)

## 1.添加Jar包
## 2.创建Application子类,并且到清单中注册
## 3.清单中注册网络权限
## 4.配置ACRA对初始化方式
~~~


//copy到继承的Application类中
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// The following line triggers the initialization of ACRA
ACRA.init(this);
}
~~~
## 5.配置错误报告网络提交的地址
~~~
@ReportsCrashes(formUri = "网络提交地址")
public class MyApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// The following line triggers the initialization of ACRA
ACRA.init(this);
}
}
~~~




## 配置Toast提示
### 1. Application配置注解
~~~
@ReportsCrashes(
 formUri = "网络提交地址",
 mode = ReportingInteractionMode.TOAST,
 resToastText = R.string.crash_toast_text)
~~~
### 2. 添加String内容
~~~
<string name="crash_toast_text">Ooooops ! I crashed, but a report has been sent to my developer to help fix the issue !</string>
~~~




## 配置Dialog提示
### 1. Application配置注解
~~~
@ReportsCrashes(
formUri = "网络提交地址",
mode = ReportingInteractionMode.DIALOG, 
resToastText = R.string.crash_toast_text, 
resDialogText = R.string.crash_dialog_text, 
resDialogTitle = R.string.crash_dialog_title, 
resDialogCommentPrompt = R.string.crash_dialog_comment_prompt, 
resDialogOkToast = R.string.crash_dialog_ok_toast
)
~~~


### 2. 添加String内容
~~~
<string name="crash_toast_text">Ooooops ! I crashed, but a report has been sent to my developer to help fix the issue !</string>


<string name="crash_dialog_title">CrashTest has crashed</string>
<string name="crash_dialog_text">An unexpected error occurred forcing the
    application to stop. Please help us fix this by sending us error data,
    all you have to do is click OK.</string>
<string name="crash_dialog_comment_prompt">You might add your comments about the problem below:</string>
<string name="crash_dialog_ok_toast">Thank you !</string>
~~~


### 3. 清单中配置Activity
~~~
<activity
android:name="org.acra.CrashReportDialog"
android:excludeFromRecents="true"
android:finishOnTaskLaunch="true"
android:launchMode="singleInstance"
android:process=":error_report"
android:theme="@style/AppBaseTheme.Dialog" >
</activity>
~~~


### 4. 添加主题样式


~~~
 <style name="AppTheme.Dialog" parent="AppBaseTheme.Dialog"/>
 
 <!-- normal -->
 <style name="AppBaseTheme.Dialog" parent="@android:style/Theme.Dialog"/>


 <!-- v11 -->
 <style name="AppBaseTheme.Dialog" parent="@android:style/Theme.Holo.Light.Dialog"/>


 <!-- v14 -->
 <style name="AppBaseTheme.Dialog" parent="@android:style/Theme.Holo.Light.Dialog"/>
~~~
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值