请问,红色部分代码的功能是什么?

huabinsir 2013-01-22 07:13:47
请问,红色部分代码的功能是什么? 谢谢

for (int result = 0; result < mSrec.getResultCount() &&
intents.size() < examineLimit; result++) {

// parse the semanticMeaning string and build an Intent
String conf = mSrec.getResult(result, Recognizer.KEY_CONFIDENCE);
String literal = mSrec.getResult(result, Recognizer.KEY_LITERAL);
String semantic = mSrec.getResult(result, Recognizer.KEY_MEANING);
String msg = "conf=" + conf + " lit=" + literal + " sem=" + semantic;
if (false) Log.d(TAG, msg);
int confInt = Integer.parseInt(conf);
if (highestConfidence < confInt) highestConfidence = confInt;
if (confInt < MINIMUM_CONFIDENCE || confInt * 2 < highestConfidence) {
if (false) Log.d(TAG, "confidence too low, dropping");
break;
}
if (mLogger != null) mLogger.logLine(msg);
String[] commands = semantic.trim().split(" ");


// DIAL 650 867 5309
if ("DIAL".equalsIgnoreCase(commands[0])) {
}
// "CALL VoiceMail"
else if ("voicemail".equalsIgnoreCase(commands[0]) && commands.length == 1) {
addCallIntent(intents, Uri.fromParts("voicemail", "x", null),
literal, "", Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
}
// "REDIAL"
else if ("redial".equalsIgnoreCase(commands[0]) && commands.length == 1) {
}
// "Intent ..."
else if ("Intent".equalsIgnoreCase(commands[0])) {
for (int i = 1; i < commands.length; i++) {
try {
Intent intent = Intent.getIntent(commands[i]);
if (intent.getStringExtra(SENTENCE_EXTRA) == null) {
intent.putExtra(SENTENCE_EXTRA, literal);
}
addIntent(intents, intent);
} catch (URISyntaxException e) {
if (false) {
Log.d(TAG, "onRecognitionSuccess: poorly " +
"formed URI in grammar" + e);
}
}
}
}
// "OPEN ..."
else if ("OPEN".equalsIgnoreCase(commands[0]) && mAllowOpenEntries) {
PackageManager pm = mActivity.getPackageManager();
if (commands.length > 1 & mOpenEntries != null) {
// the semantic value is equal to the literal in this case.
// We have to do the mapping from this text to the
// componentname ourselves. See Bug: 2457238.
// The problem is that the list of all componentnames
// can be pretty large and overflow the limit that
// the recognizer has.
String meaning = mOpenEntries.get(commands[1]);
String[] components = meaning.trim().split(" ");
for (int i=0; i < components.length; i++) {
String component = components[i];
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory("android.intent.category.VOICE_LAUNCH");
String packageName = component.substring(
0, component.lastIndexOf('/'));
String className = component.substring(
component.lastIndexOf('/')+1, component.length());
intent.setClassName(packageName, className);
List<ResolveInfo> riList = pm.queryIntentActivities(intent, 0);
for (ResolveInfo ri : riList) {
String label = ri.loadLabel(pm).toString();
intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory("android.intent.category.VOICE_LAUNCH");
intent.setClassName(packageName, className);
intent.putExtra(SENTENCE_EXTRA, literal.split(" ")[0] + " " + label);
addIntent(intents, intent);
}
}
}
}

// can't parse result
else {
if (false) Log.d(TAG, "onRecognitionSuccess: parse error");
}
}
// //end for (int result = 0; result < mSrec.getResultCount()

...全文
174 4 点赞 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
veardn 2013-01-23
打开声音控制?
  • 打赏
  • 举报
回复
xialiangdancer 2013-01-23
完全没看懂 这段代码出自哪个功能 LZ都不说清楚
  • 打赏
  • 举报
回复
huabinsir 2013-01-23
是命令行的解析
  • 打赏
  • 举报
回复
FCARM 2013-01-22
哪里的代码啊?
  • 打赏
  • 举报
回复
相关推荐
发帖
Android
加入

7.9w+

社区成员

移动平台 Android
申请成为版主
帖子事件
创建了帖子
2013-01-22 07:13
社区公告
暂无公告