kad*_*rud 16 android android-intent
我想在我的应用程序中重用Intent.ACTION_BUG_REPORT,作为获取用户反馈的简单方法.
Google地图将其用作"反馈"选项.但我没有成功解雇这一事件.
我正在使用以下内容onOptionsItemSelected(MenuItem item):
Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
在我的AndroidManifest.xml身上我已经宣布以下内容Activity:
<intent-filter>
<action android:name="android.intent.action.BUG_REPORT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
但是,当我选择选项时,除了屏幕"闪烁"之外似乎没有任何事情发生.应用程序或意图不会崩溃,它不会记录任何内容.在仿真器和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 评论中的链接的帮助下解决了这个问题。使用Android上内置的反馈机制。
在我的中,AndroidManifest.xml我将以下内容添加到<Activity>我想要调用反馈代理的位置。
<intent-filter>
<action android:name="android.intent.action.APP_ERROR" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
我做了一个简单的方法称为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);
}
}
Run Code Online (Sandbox Code Playgroud)
从我的角度来说,SettingsActivity我这样称呼它:
findPreference(sFeedbackKey).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public final boolean onPreferenceClick(Preference paramAnonymousPreference) {
sendFeedback();
finish();
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
调用该方法时sendFeedback(),将打开“使用完成操作”对话框,用户可以在其中从三个操作/图标中进行选择。

调用应用程序,返回应用程序、Google Play 和反馈代理。选择Google Play Store或Send feedback将按预期打开内置 Android 反馈代理。

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