如何使用Intent.ACTION_APP_ERROR作为一个&QUOT的手段;反馈"框架的Andr​​oid?作为一个、如何使用、框架、手段

2023-09-12 22:48:13 作者:芣烺嫚嶵洺

我想重用Intent.ACTION_BUG_REPORT在我的应用程序,以获取用户反馈的简单方法。

I would like to reuse the Intent.ACTION_BUG_REPORT in my app, as a simple means of getting user feedback.

谷歌地图使用它作为自己的反馈选项。但是我还没有成功地发射了此次活动。

Google Maps uses it as their "Feedback" option. But I've not been successful in firing the event.

我使用了 onOptionsItemSelected(菜单项项)以下

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

在我的的Andr​​oidManifest.xml 我已经声明在我的活动如下:

And in my AndroidManifest.xml I've declared the following under my Activity:

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

不过,好像没有什么改变,除了在屏幕上闪烁当我选择的选项。该应用程序或意图不会崩溃,也不会记录任何东西。无论是在模拟器和ICS 4.0.4设备上试了一下。

However, nothing seems to happen besides the screen "blink" when I select the option. The App or intent doesn't crash, it doesn't log anything. Tried it both in the Emulator and on an ICS 4.0.4 device.

我clealy失去了一些东西,但什么?

I'm clealy missing something, but what?

Intent.ACTION_APP_ERROR (恒 android.intent.action.BUG_REPORT )的加入API 14级,http://developer.android.com/reference/android/content/Intent.html#ACTION_APP_ERROR

Intent.ACTION_APP_ERROR (constant android.intent.action.BUG_REPORT) was added in API level 14, http://developer.android.com/reference/android/content/Intent.html#ACTION_APP_ERROR

推荐答案

这是解决了从@TomTasche评论上面的链接帮助。 使用内置的反馈机制,在Android 。

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

在我的的Andr​​oidManifest.xml 添加以下到&LT;活动&GT; ,我想打电话给反馈代理的。

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>

和我做了一个名为 sendFeedback()($ C $从TomTasche博文三)

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

和从我的 SettingsActivity 我这样称呼它:

And from my SettingsActivity I call it like:

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

验证与Android合作的 2.3.7 和 4.2.2

sendFeedback()方法被调用, - 对话被打开,用户可以从三个动作/图标中选择。一个用完整的行动

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.

调用应用程序,它返回到应用程序,谷歌播放和反馈剂。选择任一谷歌Play商店发送反馈将打开内置的预期Android的反馈代理。

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.

我还没有进一步的调查,如果有可能跳过-Step的使用完整的行动,它可能是可能的传递到意图正确的参数。到目前为止,这不正是我想要的了。

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.