【问题标题】:Starting Settings Activity from Preferences XML works in 2.x but not in 4.x从首选项 XML 启动设置活动在 2.x 中有效,但在 4.x 中无效
【发布时间】:2013-08-14 02:49:26
【问题描述】:

我正在使用the following techniqueText-to-Speech Settings 添加到我的应用偏好屏幕:

<Preference android:key="TTS Preferenes"
    android:title="TTS Settings"
    android:summary="A convenience shortcut instead of pressing HOME then Setting then scrolling down then pressing Text-to-Speech Settings">   
        <intent android:targetPackage="com.android.settings"
    android:targetClass="com.android.settings.TextToSpeechSettings" />
    </Preference>

它在 Android 2.x 中运行良好,但在 Android 4.0.4 中会产生异常:

E/AndroidRuntime(2663): android.content.ActivityNotFoundException: 
 Unable to find explicit activity class {com.android.settings/com.android.settings.TextToSpeechSettings}; 
  have you declared this activity in your AndroidManifest.xml?

这是为什么? Android 4(或 3?)有什么变化使这种技术不兼容?系统的 TextToSpeechSettings 首选项屏幕的名称是否已更改?

另外,我很确定它与 Manifest 文件无关,但为了安全起见,我在 Manifest 中添加了:

  <activity android:name="com.android.settings.TextToSpeechSettings"
            android:label="Text-to-Speech Settings">
  </activity>

这并没有改变任何事情。同样的 ActivityNotFoundException 问题。

在寻找解释的过程中,我找到了this thread,但它没有提到任何操作系统版本差异,所以我不确定它是否适用于此。

关于为什么以及如何解决这个问题的任何提示?

【问题讨论】:

  • 您是否尝试过“com.android.settings.tts.TextToSpeechSettings”?
  • BillTheApe 谢谢。是的,我也尝试在两者之间插入.tts.,但这没有帮助。

标签: android android-manifest android-4.0-ice-cream-sandwich android-preferences preferenceactivity


【解决方案1】:

看来这确实是一个 ICS 问题,因为 this answer 建议使用此代码:

intent = new Intent();
intent.setAction("com.android.settings.TTS_SETTINGS");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);

【讨论】:

  • 听起来很有希望,但我如何从首选项 XML 中启动它???我尝试创建自己的调用此代码的 PreferenceActivity,但我仍然得到相同的异常(只是现在使用我自己的活动而不是 com.android.settings.TextToSpeechSettings)。看起来@ehartwell 是对的:如果不是完全相同的包,就无法启动意图?
猜你喜欢
  • 2011-11-08
  • 1970-01-01
  • 2014-09-10
  • 1970-01-01
  • 1970-01-01
  • 2015-07-22
  • 2017-01-06
  • 2016-07-07
  • 1970-01-01
相关资源
最近更新 更多