How to use Intent.ACTION_APP_ERROR as a means for a “feedback” framework in Android?

This was solved with the help from the link in @TomTasche comment above. Use built-in feedback mechanism on Android.

In my AndroidManifest.xml I added the following to the <Activity> where I want to call the Feedback agent from.

<intent-filter>
   <action android:name="android.intent.action.APP_ERROR" />
   <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

And I made a simple method called sendFeedback() (code from TomTasche blogpost)

@SuppressWarnings("unused")
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void sendFeedback() {
    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);
    }
}

And from my SettingsActivity I call it like:

      findPreference(sFeedbackKey).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
          public final boolean onPreferenceClick(Preference paramAnonymousPreference) {
              sendFeedback();
              finish();
              return true;
          }
      });         

Verified working with Android 2.3.7 and 4.2.2.

When the sendFeedback() method is called, a “Complete action using”-dialog is opened where the user can select from three actions/icons.

Complete action using

The calling app, which returns to the app, and Google Play and the Feedback agent. Selecting either Google Play Storeor Send feedback will open the built-in Android feedback agent as intended.

Send feedback

I haven’t investigated further if it’s possible to skip the “Complete action using”-step, it’s probably possible with the correct parameters passed to the Intent. So far, this does exactly what I wanted for now.

Leave a Comment