@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
String incoming = intent.getStringExtra("ns");
Toast.makeText(getBaseContext(), incoming, Toast.LENGTH_SHORT).show();
String msgspeech = "Phone state changed to " + incoming;
if (msgspeech != null) {
tts.speak(msgspeech, TextToSpeech.QUEUE_FLUSH, null);
}
return START_STICKY;
}
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
}
if (!TextUtils.isEmpty(msg)) {
speakOut(msg);
} else {
speakOut("Error");
Log.e("TTS", "Initilization Failed!");
}
} else {
Log.d("SpeakService", "Could not initialize TextToSpeech.");
}
}
private void speakOut(String msg) {
tts.speak(msg, TextToSpeech.QUEUE_FLUSH, null);
}
上面的代码说出了号码,我想要怎么说出呼叫者的名字而不是号码。如何使用联系人姓名比较说话号码?
答案 0 :(得分:0)
你有这个号码。 您可以使用该号码在联系人列表中查找联系人姓名。
见帖子:How to retrieve the contact name from incoming call number?