Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use built-in feedback mechanism on Android
// more information here: http://blog.tomtasche.at/2012/10/use-built-in-feedback-mechanism-on.html
try {
int i = 3 / 0;
} catch (Exception e) {
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);
}
@jayeshcp

This comment has been minimized.

Copy link

@jayeshcp jayeshcp commented Aug 23, 2013

I like the way this brings "Send Feedback" like the original Android Feedback reporting mechanism. However, I have following problems:

1). Report says "Crash Report" and "Arithmetic Exception" ! There is no workaround for this. If exception is not raised, this cannot be done. There is no other type than TYPE_CRASH for this to work !
2). No way to pre-popolate the message field. I tried the crash.exceptionMessage = "custom message here", but it doesn't work.
If these two issues are resolved, I think this can be widely used by developers.

Thanks again for sharing this.
Jay

@satyadeepk

This comment has been minimized.

Copy link

@satyadeepk satyadeepk commented Nov 9, 2013

Thanks for the great help!
To avoid the "Complete action using..." dialog, set this on the intent.
intent.setClassName("com.google.android.feedback", "com.google.android.feedback.FeedbackActivity");

You can see my fork https://gist.github.com/satyadeepk/7389938 for the update.

@alorma

This comment has been minimized.

Copy link

@alorma alorma commented Mar 29, 2014

Any way. where is feedback sent? Play console?

@jaredsburrows

This comment has been minimized.

Copy link

@jaredsburrows jaredsburrows commented Aug 2, 2015

@alorma Yes.

@ramiloif

This comment has been minimized.

Copy link

@ramiloif ramiloif commented Jul 29, 2016

Is there a to use this on users request from menu ? Without any stack trace
I just tried this and didn't see the feedback on the Developer Console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment