0
我正在使用TextToSpeech向聯繫人中的某個人發送短信。我用一種非常難看的方式來做到這一點,因爲我需要以一種方式說出「發送消息到聯繫人文本消息是你好」的所有表達式。這將是更好的東西像「發送消息」,應用程序問我誰和繼續以這種方式..因此,我可以與應用程序如谷歌現在以dinamically方式進行交互。我至今使用的代碼是這一個: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;
}
,如果它沒有找到任何corrispondance它問我,在我接觸正確的名稱進行搜索。順便說一句,我想要做什麼?謝謝
Mmh有趣..但我認爲這很容易看到一個例子..您的應用程序是否打開?我可以看看代碼嗎?謝謝 –