请问,红色部分代码的功能是什么? 谢谢 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()
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()
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货