我在 coupleplaces 中读到无法在三星设备上为 EditText 打开拼写检查......所以它一定是真的,对吧?如果是这样,可能还有其他设备也无法进行拼写检查,例如我妻子刚从 Verizon 购买的 LG VK700 平板电脑(不要问)。

有没有办法以编程方式检测设备是否可以进行拼写检查? 我想要一个让用户打开或关闭它的选项,但如果它无法打开就不行。然后我希望该选项变灰。

(谷歌搜索 programmatically determine whether android device can spellcheck 出现了 this ,这看起来很有趣,但我无法为大多数用户可能会关闭或忽略的东西做很多工作(学习速度慢,这里),因为标记的单词只会出现在列表中与用户的“单词模式”匹配的单词(例如 p?tt??n ),用于解决单词难题。)

最佳答案

根据 Android Spell Checker Framework documentation ,拼写检查服务应该在应用程序的 list 中公开为具有特定 Intent 过滤器和元数据标签的服务:

<service
    android:label="@string/app_name"
    android:name=".SampleSpellCheckerService"
    android:permission="android.permission.BIND_TEXT_SERVICE" >
    <intent-filter >
        <action android:name="android.service.textservice.SpellCheckerService" />
    </intent-filter>

    <meta-data
        android:name="android.view.textservice.scs"
        android:resource="@xml/spellchecker" />
</service>

因此,合理地,我们应该能够通过尝试解析匹配的 Intent 来检测是否安装了任何此类服务。

我没有三星设备来测试“未找到”的情况,但我认为这应该有效:
TextView tv = new TextView(this);
PackageManager pm = getPackageManager();
Intent spell = new Intent(SpellCheckerService.SERVICE_INTERFACE);
ResolveInfo info = pm.resolveService(spell, 0);
if (info == null) {
    tv.setText("no spell checker found");
} else {
    tv.setText("found spell checker " + info.serviceInfo.name + " in package " + info.serviceInfo.packageName);
}

无论我在“设置”中启用还是禁用拼写检查,我的 Moto G (2013) 都会说: android - 有没有办法以编程方式确定android设备是否内置了拼写检查器?-LMLPHP

这是与 vanilla AOSP 键盘相同的包。我认为有问题的三星手机已经用他们自己的键盘替换了那个包,而不替换拼写检查服务?

请注意,即使您检测到匹配服务的存在,激活它的实际设置也可能因设备而异......

关于android - 有没有办法以编程方式确定android设备是否内置了拼写检查器?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32725258/

10-09 04:54