我正在使用TextToSpeech向我的联系人中的某人发送短信。我用一种非常丑陋的方式来做这件事,因为我需要说所有表达式"发送消息给联系人短信是你好"在某种程度上。像#"发送消息"会更好。并且应用程序问我是谁,然后以这种方式继续..所以我现在可以像谷歌一样以谷歌的方式与应用程序进行交互。我到目前为止使用的代码就是这个:
if(resultList.getText().toString().toLowerCase().contains(getResources().getString(R.string.messaggio))) //invio sms
{
splitMessage = message.split(getResources().getString(R.string.destinatario), 2);
if(splitMessage.length>1){
if((splitMessage[0].trim()).equalsIgnoreCase(getResources().getString(R.string.inviamessaggio)))
{
splitMessage[0] = "message";
splitMessage[1] = splitMessage[1].trim();
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
splitMessageWithNameAndBody = splitMessage[1].split(getResources().getString(R.string.testomessaggio), 2);
if(splitMessageWithNameAndBody.length>1)
{
splitMessage[0] = "text message";
while (phones.moveToNext())
{
String Name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String Number=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
splitMessage[1] = splitMessageWithNameAndBody[0].trim();
splitMessageWithNameAndBody[1] = splitMessageWithNameAndBody[1].trim();
if(Name.compareToIgnoreCase(splitMessage[1])== 0)
{
nameMatchFound = true;
flag=1;
String url = "sms:"+Number;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.putExtra("sms_body", splitMessageWithNameAndBody[1]);
startActivity(intent);
}
}
if(!nameMatchFound)
{
Toast.makeText(getApplicationContext(), "Contatto non trovato o ci sono più corrispondenze", Toast.LENGTH_SHORT).show();
DialogFragment df=new DialogTrial();
df.show(getSupportFragmentManager(), "MyDialog");
}
} else {
//Toast.makeText(getApplicationContext(), "Please say contact name followed by call or message keyword", Toast.LENGTH_LONG).show();
while (phones.moveToNext()){
String Name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String Number=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
if(Name.compareToIgnoreCase(splitMessage[1]) == 0){
nameMatchFound = true;
String url = "sms:"+Number;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.putExtra("sms_body", splitMessageWithNameAndBody[1]);
startActivity(intent);
}
}
}
}
else
{
Toast.makeText(getApplicationContext(), "Please say contact name followed by call keyword", Toast.LENGTH_LONG).show();
}
}
//break;
}
如果它没有找到任何相关信息,它会要求我在我的联系人中搜索正确的名称。顺便说一下,我想做的可能吗?感谢
答案 0 :(得分:1)
有可能吗?当然。我有一个我编写的应用程序类似的东西 - 它会读出一个文本,询问您是否要响应,然后询问响应(如果是),然后读取它并在发送前请求确认。通常,您需要创建一个状态机,以便您知道如何在响应时处理响应以及在下一次输入时说出什么。