IntentNotFoundException的TextToSpeech.Engine.ACTION_INSTALL_TTS_DATATextToSpeech、IntentNotFoundExcept

由网友(蓝鲸鱼)分享简介:我想通过以下的在Android开发者博客这篇文章。这表明以下$ C $下,如果其不支持安装文本到语音数据。I am trying to implement text to speech by following this article on the Android Developers Blog. It sugge...

我想通过以下的在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.

阅读全文

相关推荐

最新文章