android.content.Intent#ACTION_APP_ERROR源码实例Demo

下面列出了android.content.Intent#ACTION_APP_ERROR 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Return activity in receiverPackage that handles ACTION_APP_ERROR.
 *
 * @param pm PackageManager instance
 * @param errorPackage package which caused the error
 * @param receiverPackage candidate package to receive the error
 * @return activity component within receiverPackage which handles
 * ACTION_APP_ERROR, or null if not found
 */
static ComponentName getErrorReportReceiver(PackageManager pm, String errorPackage,
        String receiverPackage) {
    if (receiverPackage == null || receiverPackage.length() == 0) {
        return null;
    }

    // break the loop if it's the error report receiver package that crashed
    if (receiverPackage.equals(errorPackage)) {
        return null;
    }

    Intent intent = new Intent(Intent.ACTION_APP_ERROR);
    intent.setPackage(receiverPackage);
    ResolveInfo info = pm.resolveActivity(intent, 0);
    if (info == null || info.activityInfo == null) {
        return null;
    }
    return new ComponentName(receiverPackage, info.activityInfo.name);
}
 
源代码2 项目: android_9.0.0_r45   文件: AppErrors.java
Intent createAppErrorIntentLocked(ProcessRecord r,
        long timeMillis, ApplicationErrorReport.CrashInfo crashInfo) {
    ApplicationErrorReport report = createAppErrorReportLocked(r, timeMillis, crashInfo);
    if (report == null) {
        return null;
    }
    Intent result = new Intent(Intent.ACTION_APP_ERROR);
    result.setComponent(r.errorReportReceiver);
    result.putExtra(Intent.EXTRA_BUG_REPORT, report);
    result.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return result;
}
 
源代码3 项目: tracker-control-android   文件: Util.java
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));
    }
}
 
源代码4 项目: Capstone-Project   文件: CoreUtils.java
/**
 * 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);
    }
}
 
源代码5 项目: gito-github-client   文件: Utils.java
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);
    }
}
 
源代码6 项目: kcanotify   文件: Util.java
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));
    }
}
 
源代码7 项目: NetGuard   文件: Util.java
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));
    }
}
 
源代码8 项目: AndroidWearCrashReport   文件: CrashReport.java
@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;
}
 
 方法所在类
 同类方法