Launch FeedbackActivity in my application like in Android Hangouts

旧城冷巷雨未停 提交于 2019-12-03 12:22:09

So it seems that this is possible, bur report is not visible in Developer console.

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
protected Intent prepareIcsFeedbackIntent(Activity activity, PackageManager packageManager) {
    ApplicationErrorReport localApplicationErrorReport = new ApplicationErrorReport();
    localApplicationErrorReport.packageName = activity.getPackageName();

    localApplicationErrorReport.type = 11;
    localApplicationErrorReport.installerPackageName = packageManager.getInstallerPackageName(
            localApplicationErrorReport.packageName);

    return getAppErrortIntent().putExtra(Intent.EXTRA_BUG_REPORT, localApplicationErrorReport);
}

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
protected Intent getAppErrortIntent() {
    Intent localIntent = new Intent(Intent.ACTION_APP_ERROR)
            .addCategory(Intent.CATEGORY_DEFAULT)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return localIntent;
}

Although it's not exactly the same, you can programmatically invoke a crash-report-dialog:

ApplicationErrorReport report = new ApplicationErrorReport();
report.packageName = report.processName = 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);
startActivity(intent);

More information here: http://blog.tomtasche.at/2012/10/use-built-in-feedback-mechanism-on.html

Just re-create that layout on a .xml file and create a Class that extends FragmentActivity (as the Google Hangouts App seems to do) or create a Class that extends DialogFragment to handle its logic.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!