1. 程式人生 > >錯誤日誌的收集(ACRA的使用教程)

錯誤日誌的收集(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"/>
~~~