IntentNotFoundException的TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA [英] IntentNotFoundException for TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA

查看:286
本文介绍了IntentNotFoundException的TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过以下的在Android开发者博客这篇文章。这表明以下$ C $下,如果其不支持安装文本到语音数据。

I am trying to implement text to speech by following this article on the Android Developers Blog. It suggests the following code for installing text to speech data if it is not supported.

Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);

这将引发异常

ActivityNotFoundException :无活动   发现处理意向

ActivityNotFoundException: No activity found to handle Intent

不过,我现在用的是code的这里确定实际支持的意图。这里是再presentation列表:

However, I am using the code here to determine the the intent is actually supported. Here is the list representation:

[ResolveInfo{43cc5280 com.svox.pico.DownloadVoiceData p=0 o=0 m=0x108000}]

为什么没有这项工作?

Why doesn't this work?

更新

我不知道为什么,但似乎现在的工作。

I don't know why, but it seems to work now.

推荐答案

要检查的意图是否真正支持与否,请使用以下code:

To check whether the intent is actually supported or not, use the following code :

PackageManager pm = getPackageManager();
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
ResolveInfo resolveInfo = pm.resolveActivity( installIntent, PackageManager.MATCH_DEFAULT_ONLY );

if( resolveInfo == null ) {
   // Not able to find the activity which should be started for this intent
} else {
   startActivity( installIntent );
}

如果它不能够找到使用resolveActivity()的活性那么它意味着该活动需要不设置其中的一些其他参数。在这种情况下,你应该使用queryIntentActivities(类名),并设置了意向组件/类的名称。

If it is not able to find the activity using resolveActivity() then it means that the activity requires some other parameters which are not provided. In that case, you should get the class name using the queryIntentActivities() and set the intent component/class name.

这篇关于IntentNotFoundException的TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆