Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 从首选项启动设置活动XML在2.x中运行,但在4.x中不运行大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用 the following technique将文本转语音设置添加到我应用的首选项屏幕:

<Preference android:key="TTS Preferenes"
    android@R_345_6964@="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,但它没有提到任何操作系统版本的差异,所以我不确定它是否适用于此.

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

解决方法

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

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

大佬总结

以上是大佬教程为你收集整理的android – 从首选项启动设置活动XML在2.x中运行,但在4.x中不运行全部内容,希望文章能够帮你解决android – 从首选项启动设置活动XML在2.x中运行,但在4.x中不运行所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。