1
當用戶在3秒後自動發送完成消息時,如何發送消息而無需使用任何按鈕自動發送至所需號碼假設此處輸入的接收者號碼是我的代碼。如何在不使用任何按鈕的情況下發送短信
public void onActivityResult(int requestCode, int resultCode, Intent data){
ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
String topResult = matches.get(0);
EditText editText = (EditText)findViewById(R.id.editTextmessage);
EditText editText1 = (EditText)findViewById(R.id.toNumber);
String phoneNo = null;
String sms = null;
switch(requestCode){
case check1:
editText1.setText(topResult);
phoneNo=editText1.getText().toString();
break;
case check:
editText.setText(topResult);
sms=editText.getText().toString();
break;
}
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "Your Message Sent Successfully",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"Sending fail, Please try again!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
super.onActivityResult(requestCode, resultCode, data);
}