Java Code Examples for android.app.ApplicationErrorReport#TYPE_CRASH

The following examples show how to use android.app.ApplicationErrorReport#TYPE_CRASH . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReportHandler.java    From android-crash-reporting with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static void showDefaultReportActivity(Context context, Throwable th)
{
	String packageName = context.getPackageName();
	PackageManager pm = context.getPackageManager();
	
	// Not perfect.. but it'll have to do.
	ApplicationErrorReport report = new ApplicationErrorReport();
	report.installerPackageName   = pm.getInstallerPackageName(packageName);
	report.packageName = packageName;
	report.processName = packageName;
	report.time        = System.currentTimeMillis();
	report.systemApp   = false;
	report.type        = ApplicationErrorReport.TYPE_CRASH;
	report.crashInfo   = new ApplicationErrorReport.CrashInfo(th);
	
	sAppContext.startActivity(new Intent(Intent.ACTION_APP_ERROR)
		.setPackage("com.google.android.feedback")
		.putExtra(Intent.EXTRA_BUG_REPORT, report)
		.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
 
Example 2
Source File: AppErrors.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private ApplicationErrorReport createAppErrorReportLocked(ProcessRecord r,
        long timeMillis, ApplicationErrorReport.CrashInfo crashInfo) {
    if (r.errorReportReceiver == null) {
        return null;
    }

    if (!r.crashing && !r.notResponding && !r.forceCrashReport) {
        return null;
    }

    ApplicationErrorReport report = new ApplicationErrorReport();
    report.packageName = r.info.packageName;
    report.installerPackageName = r.errorReportReceiver.getPackageName();
    report.processName = r.processName;
    report.time = timeMillis;
    report.systemApp = (r.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;

    if (r.crashing || r.forceCrashReport) {
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.crashInfo = crashInfo;
    } else if (r.notResponding) {
        report.type = ApplicationErrorReport.TYPE_ANR;
        report.anrInfo = new ApplicationErrorReport.AnrInfo();

        report.anrInfo.activity = r.notRespondingReport.tag;
        report.anrInfo.cause = r.notRespondingReport.shortMsg;
        report.anrInfo.info = r.notRespondingReport.longMsg;
    }

    return report;
}
 
Example 3
Source File: Util.java    From tracker-control-android with GNU General Public License v3.0 5 votes vote down vote up
public static void sendCrashReport(Throwable ex, final Context context) {
    if (!isPlayStoreInstall(context) || Util.isDebuggable(context))
        return;

    try {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = context.getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;

        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = ex.getClass().getSimpleName();
        crash.exceptionMessage = ex.getMessage();

        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        ex.printStackTrace(printer);

        crash.stackTrace = writer.toString();

        StackTraceElement stack = ex.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();

        report.crashInfo = crash;

        final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
        bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
        bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bug.resolveActivity(context.getPackageManager()) != null)
            context.startActivity(bug);
    } catch (Throwable exex) {
        Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex));
    }
}
 
Example 4
Source File: CoreUtils.java    From Capstone-Project with MIT License 5 votes vote down vote up
/**
 * Manually create an exception and open system error reporting window.
 * Source: https://github.com/DmitryMalkovich/github-analytics/blob/master/app/src/main/java/com/dmitrymalkovich/android/githubanalytics/util/ActivityUtils.java#L64
 *
 * @param activity Current activity
 */
public static void openFeedback(Activity activity) {
    try {
        throw new Exception();
    } catch (Exception e) {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = activity.getApplication()
                .getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;
        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = e.getClass().getSimpleName();
        crash.exceptionMessage = e.getMessage();
        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        e.printStackTrace(printer);
        crash.stackTrace = writer.toString();
        StackTraceElement stack = e.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();
        report.crashInfo = crash;
        Intent intent = new Intent(Intent.ACTION_APP_ERROR);
        intent.putExtra(Intent.EXTRA_BUG_REPORT, report);
        activity.startActivity(intent);
    }
}
 
Example 5
Source File: Utils.java    From gito-github-client with Apache License 2.0 5 votes vote down vote up
public static void openFeedback(Activity activity) {
    try {
        throw new IOException();
    } catch (IOException e) {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = activity.getApplication()
                .getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;
        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = e.getClass().getSimpleName();
        crash.exceptionMessage = e.getMessage();
        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        e.printStackTrace(printer);
        crash.stackTrace = writer.toString();
        StackTraceElement stack = e.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();
        report.crashInfo = crash;
        Intent intent = new Intent(Intent.ACTION_APP_ERROR);
        intent.putExtra(Intent.EXTRA_BUG_REPORT, report);
        activity.startActivity(intent);
    }
}
 
Example 6
Source File: Util.java    From kcanotify with GNU General Public License v3.0 5 votes vote down vote up
public static void sendCrashReport(Throwable ex, final Context context) {
    if (!isPlayStoreInstall(context) || Util.isDebuggable(context))
        return;

    try {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = context.getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;

        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = ex.getClass().getSimpleName();
        crash.exceptionMessage = ex.getMessage();

        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        ex.printStackTrace(printer);

        crash.stackTrace = writer.toString();

        StackTraceElement stack = ex.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();

        report.crashInfo = crash;

        final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
        bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
        bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bug.resolveActivity(context.getPackageManager()) != null)
            context.startActivity(bug);
    } catch (Throwable exex) {
        Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex));
    }
}
 
Example 7
Source File: Util.java    From NetGuard with GNU General Public License v3.0 5 votes vote down vote up
public static void sendCrashReport(Throwable ex, final Context context) {
    if (!isPlayStoreInstall(context) || Util.isDebuggable(context))
        return;

    try {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = context.getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;

        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = ex.getClass().getSimpleName();
        crash.exceptionMessage = ex.getMessage();

        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        ex.printStackTrace(printer);

        crash.stackTrace = writer.toString();

        StackTraceElement stack = ex.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();

        report.crashInfo = crash;

        final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
        bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
        bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bug.resolveActivity(context.getPackageManager()) != null)
            context.startActivity(bug);
    } catch (Throwable exex) {
        Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex));
    }
}
 
Example 8
Source File: CrashReport.java    From AndroidWearCrashReport with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void reportToPlayStore(Context c) {
    if (currentCrashInfo == null || currentException == null) {
        return;
    }
    ApplicationErrorReport applicationErrorReport = new ApplicationErrorReport();

    applicationErrorReport.packageName = this.context.getPackageName();
    applicationErrorReport.processName = this.context.getPackageName();
    applicationErrorReport.time = System.currentTimeMillis();
    applicationErrorReport.systemApp = false;

    ///////////
    // CRASH //
    ///////////

    applicationErrorReport.type = ApplicationErrorReport.TYPE_CRASH;

    ApplicationErrorReport.CrashInfo crashInfo = new ApplicationErrorReport.CrashInfo();
    crashInfo.exceptionClassName = currentException.getClass().getSimpleName();
    crashInfo.exceptionMessage = currentException.getMessage();
    crashInfo.stackTrace = currentCrashInfo.toString() + " - " +Utils.getStackTrace(currentException);

    StackTraceElement stackTraceElement = currentException.getStackTrace()[0];
    crashInfo.throwClassName = stackTraceElement.getClassName();
    crashInfo.throwFileName = stackTraceElement.getFileName();
    crashInfo.throwMethodName = stackTraceElement.getMethodName();
    crashInfo.throwLineNumber = stackTraceElement.getLineNumber();

    applicationErrorReport.crashInfo = crashInfo;

    Intent i = new Intent(Intent.ACTION_APP_ERROR);
    i.putExtra(Intent.EXTRA_BUG_REPORT, applicationErrorReport);
    if (!(c instanceof Activity)) {
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }

    // Force "Send feedback choice", but still needs user acknowledgement
    i.setClassName("com.google.android.feedback", "com.google.android.feedback.FeedbackActivity");

    c.startActivity(i);
    currentCrashInfo = null;
    currentException = null;
}