android 利用acra發送crashReport

來源:互聯網
上載者:User
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 = "fenghanlu@163.com",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 secondsresDialogText = R.string.crash_dialog_text,resDialogIcon = android.R.drawable.ic_dialog_info, //optional. default is a warning signresDialogTitle = R.string.crash_dialog_title, // optional. default is your application nameresDialogCommentPrompt = R.string.crash_dialog_comment_prompt, // optional. when defined, adds a user text field input with this text resource as a labelresDialogOkToast = R.string.crash_dialog_ok_toast // optional. displays a Toast message when the user accepts to send a report.)public class TestApplication extends Application{@Overridepublic 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);}@Overridepublic 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或者更高版本

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.