我想在我的应用中重用 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.7 和 4.2.2 兼容。
当sendFeedback()
方法被调用时,会打开一个“使用完成操作”对话框,用户可以在其中从三个操作/图标中进行选择。
调用应用程序,返回到应用程序,以及 Google Play 和反馈代理。选择Google Play Store
或 Send feedback
将按预期打开内置的 Android 反馈代理。
我还没有进一步调查是否可以跳过“使用完成操作”步骤,可能通过传递给 Intent
的正确参数是可能的。 .到目前为止,这正是我现在想要的。
关于android - 如何使用 Intent.ACTION_APP_ERROR 作为 Android 中 "feedback"框架的一种手段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10559267/