queryIntentActivities()数据额外意向 [英] queryIntentActivities() data Intent extras

查看:448
本文介绍了queryIntentActivities()数据额外意向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是让现有的TTS语音引擎和它们各自的可用语言的。我能顺利拿到可用的引擎具有以下code:

 软件包管理系统PM = getPackageManager();    意图ttsIntent =新的Intent();
    ttsIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    // ttsIntent.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);    ArrayList的<串GT; engineInfo =新的ArrayList<串GT;();    清单< ResolveInfo>清单= pm.queryIntentActivities(ttsIntent,
            PackageManager.GET_META_DATA);    对于(ResolveInfo APPINFO:名单){
        engineInfo.add(appInfo.activityInfo.applicationInfo.packageName);
        engineInfo.add(appInfo.activityInfo.applicationInfo.loadLabel(下午)
                的ToString());
    }

上面的注释行请求的意图的额外数据。我已经做了很多的搜索,但找不到任何的 queryIntentActivities例子()以这种方式使用getExtra'或'putExtra。

我可以假设,因此,这是不是一种选择,我需要回去看了一些基础知识的地方,为什么这是不可能的!?

如果我做任何试图检索数据,我得到一个空指针,即使我检查它是否!= NULL 这是一个有点奇怪?

  appInfo.activityInfo.applicationInfo.metaData.getEtcEtc ...

任何帮助将是非常美联社preciated,先谢谢了。

postPutEXTRA: API级别是9这样的 getEngines()是不提供给我的,尽管这会涉及一个初始化对象TTS每个人,所以不理想呢。

postPutEDIT:我试过循环内的以下提取相关的UID,但它并没有为所有,但我测试语音引擎的工作之一。

  ApplicationInfo AI = NULL;
    尝试{
        AI = pm.getApplicationInfo(appInfo.activityInfo.applicationInfo.packageName,0);
    }赶上(ē的NameNotFoundException){
        e.printStackTrace();
        返回;
    }    的String [] =声音pm.getPackagesForUid(ai.uid);


解决方案

我解决不了这个问题的具体名称,但我没有得到我想要的可用语音引擎和他们的语言在设备上的信息,而用户的交互,以下列方式:

 私人无效getEngines(){    意图ttsIntent =新的Intent();
    ttsIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);    ArrayList的<串GT; engineInfo =新的ArrayList<串GT;();    软件包管理系统下午= getPackageManager();    清单< ResolveInfo>清单= pm.queryIntentActivities(ttsIntent,
            PackageManager.GET_META_DATA);    对于(ResolveInfo APPINFO:名单){
        engineInfo.add(appInfo.activityInfo.applicationInfo.packageName);        ttsIntent
                .setPackage(appInfo.activityInfo.applicationInfo.packageName);
        ttsIntent
                .getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);        startActivityForResult(ttsIntent,33);    }    如果(DE.BUG){
        MyLog.d(engineInfo:+ engineInfo.size()+:
                + engineInfo.toString());
    }
}@覆盖
公共无效的onActivityResult(INT申请code,INT结果code,意图数据){    如果(要求code == 33安培;&放大器;数据!= NULL){        ArrayList的<串GT;用=数据
                .getStringArrayListExtra(availableVoices);        如果(DE.BUG){
            MyLog.i(声音:+ available.toString());
        }
    }
}

我留在我的自定义日志类/方法来显示在那里我捕获数据。您可以重新排列上面把所有的数据整合到一个或多个全局数组列表(S)。

My aim is to get the available TTS voice engines and their respective available languages. I can successfully get the available engines with the following code:

    PackageManager pm = getPackageManager();

    Intent ttsIntent = new Intent();
    ttsIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    // ttsIntent.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);

    ArrayList<String> engineInfo = new ArrayList<String>();

    List<ResolveInfo> list = pm.queryIntentActivities(ttsIntent,
            PackageManager.GET_META_DATA);

    for (ResolveInfo appInfo : list) {
        engineInfo.add(appInfo.activityInfo.applicationInfo.packageName);
        engineInfo.add(appInfo.activityInfo.applicationInfo.loadLabel(pm)
                .toString());
    }

The commented out line above requests a data extra for the intent. I've done many searches, but can find no examples of queryIntentActivities() using 'getExtra' or 'putExtra' in this way.

Can I therefore assume, that this isn't an option and I need to go back to read some basics somewhere of why this isn't possible!?

If I make any attempt to retrieve the data, I get a null pointer, even if I'm checking if it's !=null which is a little odd?

appInfo.activityInfo.applicationInfo.metaData.getEtcEtc...

Any help would be much appreciated, thanks in advance.

postPutEXTRA: API level is 9 so getEngines() isn't available to me, although that would involve initialising a tts object for each one, so not ideal anyway.

postPutEDIT: I tried the following within the loop to extract associated uid's, but it didn't work for all but one of the voice engines I tested.

    ApplicationInfo ai = null;
    try {
        ai = pm.getApplicationInfo(appInfo.activityInfo.applicationInfo.packageName, 0);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return;
    }

    String[] voices = pm.getPackagesForUid(ai.uid);

解决方案

I couldn't solve the specific title of this question, but I did get the information I wanted of the available voice engines and their languages on the device, without user interaction, in the following way:

private void getEngines() {

    Intent ttsIntent = new Intent();
    ttsIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);

    ArrayList<String> engineInfo = new ArrayList<String>();

    PackageManager pm = getPackageManager();

    List<ResolveInfo> list = pm.queryIntentActivities(ttsIntent,
            PackageManager.GET_META_DATA);

    for (ResolveInfo appInfo : list) {
        engineInfo.add(appInfo.activityInfo.applicationInfo.packageName);

        ttsIntent
                .setPackage(appInfo.activityInfo.applicationInfo.packageName);
        ttsIntent
                .getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);

        startActivityForResult(ttsIntent, 33);

    }

    if (DE.BUG) {
        MyLog.d("engineInfo: " + engineInfo.size() + " : "
                + engineInfo.toString());
    }
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == 33 && data != null) {

        ArrayList<String> available = data
                .getStringArrayListExtra("availableVoices");

        if (DE.BUG) {
            MyLog.i("Voices: " + available.toString());
        }
    }
}

I've left in my custom logging class/method to show where I'm capturing the data. You can rearrange the above to put all of the data into one or more global array list(s).

这篇关于queryIntentActivities()数据额外意向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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