Search code examples
androidcrashandroid-4.0-ice-cream-sandwich

How to get the crash info from ApplicationErrorReport class?


Android ICS (api 14) introduced the ApplicationErrorReport class with the following info: CrashInfo BatteryInfo and ANRInfo. From the class overview it seems that this class refers to all application installed on the device and not for debugging your own personal application. I cannot seem to reach that information (simulated crashes and anr's)

I tried this code:

ApplicationErrorReport appp = new ApplicationErrorReport();
CrashInfo test = appp.crashInfo;
Log.i(test.stackTrace);

but i get that test is null

How to get the crash information?


Solution

  • In the ApplicationErrorReport API it says:

    ApplicationErrorReport()
    Create an uninitialized instance of ApplicationErrorReport.

    This means that the "type" of error is undefined, so it's not a crash report and therefore the crashinfo is null.

    EDIT: I took a look at the source code. You can instantiate the CrashInfo part via the method readFromParcel(in) where the first int in the parcel is the int corresponding to ApplicationErrorReport.TYPE_CRASH. Alternatively you can create a CrashInfo object yourself and assign it to the ApplicationErrorReport, but this again requires a parcel if you want to CrashInfo data to be filled.

    I tried looking for code where it is used, but the only thing I could find is the ApplicationManagerNative (also using parcels).

    case HANDLE_APPLICATION_CRASH_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            IBinder app = data.readStrongBinder();
            ApplicationErrorReport.CrashInfo ci = new ApplicationErrorReport.CrashInfo(data);
            handleApplicationCrash(app, ci);
            reply.writeNoException();
            return true;
    })