android - 如何使用 Intent.ACTION_APP_ERROR 作为 Android 中 "feedback"框架的一种手段?

标签 android android-intent

我想在我的应用中重用 Intent.ACTION_BUG_REPORT,作为获取用户反馈的一种简单方法。

Google map 将其用作“反馈”选项。但是我没有成功触发这个事件。

我在 onOptionsItemSelected(MenuItem item) 中使用以下内容:

    Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
    startActivity(intent);

在我的 AndroidManifest.xml 中,我在 Activity 下声明了以下内容:

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

但是,当我选择该选项时,除了屏幕“闪烁”之外似乎什么都没有发生。应用程序或 Intent 不会崩溃,它不会记录任何内容。在模拟器和 ICS 4.0.4 设备上都试过了。

我显然错过了一些东西,但是什么?

编辑

Intent.ACTION_APP_ERROR(常量android.intent.action.BUG_REPORT)被添加到API level 14中,http://developer.android.com/reference/android/content/Intent.html#ACTION_APP_ERROR

最佳答案

在上面@TomTasche 评论中的链接的帮助下解决了这个问题。 Use built-in feedback mechanism on Android .

在我的AndroidManifest.xml我在 <Activity> 中添加了以下内容我想从哪里调用反馈代理。

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

我做了一个简单的方法,叫做 sendFeedback() (来自 TomTasche 博文的代码)

@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);
    }
}

我的SettingsActivity我这样调用它:

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

已验证可与 Android 2.3.74.2.2 兼容。

sendFeedback()方法被调用时,会打开一个“使用完成操作”对话框,用户可以在其中从三个操作/图标中进行选择。

Complete action using

调用应用程序,返回到应用程序,以及 Google Play 和反馈代理。选择Google Play StoreSend feedback将按预期打开内置的 Android 反馈代理。

Send feedback

我还没有进一步调查是否可以跳过“使用完成操作”步骤,可能通过传递给 Intent 的正确参数是可能的。 .到目前为止,这正是我现在想要的。

关于android - 如何使用 Intent.ACTION_APP_ERROR 作为 Android 中 "feedback"框架的一种手段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10559267/

相关文章:

android - 列出已安装包的 Intent 过滤器

Android Studio Gradle 同步失败

android - 在android中获取存储信息

android - 如何在android中制作椭圆形tabhost

android - 在触摸事件期间从后台线程更新 UI

android - 错误的 Intent 被使用

java - 使用 ViewHolder 为 ListView 项设置 onClickListener

java - 通过 Intent 传递 list<String[]>

android - 通知用户付费版本的应用程序可用

android - 从另一个 Activity 返回后如何恢复 Activity 中最后打开的 fragment