Android Open Source - mcdroid Crash Report Writer






From Project

Back to project page mcdroid.

License

The source code is released under:

Apache License

If you think the Android project mcdroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package cn.mibcxb.acra;
//w w w  .j a  v a2s .co  m
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map.Entry;
import java.util.Properties;

import org.acra.ReportField;
import org.acra.collector.CrashReportData;
import org.acra.sender.ReportSender;
import org.acra.sender.ReportSenderException;

import android.os.Environment;
import android.text.TextUtils;
import cn.mibcxb.android.util.Logger;
import cn.mibcxb.util.McIO;

public class CrashReportWriter implements ReportSender {
    private static final String TAG = Logger
            .getSimpleTag(CrashReportWriter.class);

    private String path = "crash";

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    @Override
    public void send(CrashReportData report) throws ReportSenderException {
        File root = Environment.getExternalStorageDirectory();
        File dir = null;
        if (TextUtils.isEmpty(path)) {
            dir = new File(root, report.getProperty(ReportField.PACKAGE_NAME));
        } else {
            dir = new File(root, path + File.separator
                    + report.getProperty(ReportField.PACKAGE_NAME));
        }
        if (!dir.exists()) {
            dir.mkdirs();
        }

        String filename = System.currentTimeMillis() + "_"
                + report.getProperty(ReportField.REPORT_ID);
        File file = new File(dir, filename);

        Properties prop = new Properties();
        for (Entry<ReportField, String> entry : report.entrySet()) {
            prop.put(entry.getKey().name(), entry.getValue());
        }

        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file);
            prop.storeToXML(fos, TAG);
        } catch (FileNotFoundException e) {
            Logger.e(TAG, e.getMessage(), e);
        } catch (IOException e) {
            Logger.e(TAG, e.getMessage(), e);
        } finally {
            McIO.closeQuietly(fos);
        }
    }

}




Java Source Code List

cn.mibcxb.acra.CrashReportWriter.java
cn.mibcxb.android.app.McApplication.java
cn.mibcxb.android.os.McHandler.java
cn.mibcxb.android.util.Logger.java
cn.mibcxb.android.util.NetworkWatcher.java
cn.mibcxb.util.McIO.java
cn.mibcxb.util.McMath.java