0

我正在使用 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;

        }

如果它没有找到任何通信,它会要求我在我的联系人中搜索正确的名字。顺便说一句,我想要做的可能吗?谢谢

4

1 回答 1

1

可能吗?当然。我有一个我写的应用程序做类似的事情 - 它读出一个文本,询问你是否想回复,然后要求回复(如果是的话),然后阅读它并在发送之前要求确认。基本上你需要制作一个状态机,这样你就知道如何在响应进来时处理它,以及为下一个输入说什么。

于 2014-07-02T09:53:07.027 回答