android 利用acra發送crashReport



public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView v= null;
        v.setText("abc");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

在application中加入acra

@ReportsCrashes(formKey="dGVacG0ydVHnaNHjRjVTUTEtb3FPWGc6MQ",
mailTo = "[email protected]",
mode = ReportingInteractionMode.DIALOG,
customReportContent = { ReportField.APP_VERSION_NAME, ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL, ReportField.CUSTOM_DATA,ReportField.BRAND, ReportField.STACK_TRACE, ReportField.LOGCAT,ReportField.USER_COMMENT },
resToastText = R.string.crash_toast_text, // optional, displayed as soon as the crash occurs, before collecting data which can take a few seconds
resDialogText = R.string.crash_dialog_text,
resDialogIcon = android.R.drawable.ic_dialog_info, //optional. default is a warning sign
resDialogTitle = R.string.crash_dialog_title, // optional. default is your application name
resDialogCommentPrompt = R.string.crash_dialog_comment_prompt, // optional. when defined, adds a user text field input with this text resource as a label
resDialogOkToast = R.string.crash_dialog_ok_toast // optional. displays a Toast message when the user accepts to send a report.
)

public class TestApplication extends Application{

	@Override
	public void onCreate() {
		super.onCreate();
		ACRA.init(this);
		ErrorReporter.getInstance().removeAllReportSenders();
		ErrorReporter.getInstance().setReportSender(new CrashReportSender(getApplicationContext()));
//		ErrorReporter.getInstance().setReportSender(new AcraSender(getApplicationContext(),"http://10.32.202.155:9876"));
		
	}

}

自定義sender

ublic class CrashReportSender implements ReportSender{
	private final Context mContext;
	public final static String formUri="http://10.32.202.155:9876";
	public CrashReportSender(Context mContext) {
		super();
		this.mContext = mContext;
		ACRA.getErrorReporter().putCustomData("PLATFORM", "ANDROID");
		ACRA.getErrorReporter().putCustomData("BUILD_ID", android.os.Build.ID);		
		ACRA.getErrorReporter().putCustomData("DEVICE_NAME", android.os.Build.PRODUCT);		

	}

	@Override
	public void send(CrashReportData arg0) throws ReportSenderException {

	EmailIntentSender emailSender = new EmailIntentSender(mContext);
        emailSender.send(arg0);
        // send crash report to host
        HttpPostSender httpSender = new HttpPostSender(formUri, null);
        httpSender.send(arg0);
        //send crash report to google
        GoogleFormSender googleSender =new GoogleFormSender();
        googleSender.send(arg0);



	}
AndroidManifest.xml中加入註冊

   <activity
            android:name="org.acra.CrashReportDialog"
            android:excludeFromRecents="true"
            android:finishOnTaskLaunch="true"
            android:launchMode="singleInstance"
            android:theme="@android:style/Theme.Dialog" />



注:acra版本必須是4.4.0或者更高版本



發佈了49 篇原創文章 · 獲贊 8 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章