2013-12-15 75 views
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); 


} 

回答

1

當用戶完成輸入或關閉,你可以有一個定時器啓動鍵盤,如果計時器達到3秒,然後發送郵件,如果用戶停止定時器(重新打開鍵盤或類型的一些超過你重置計時器回到三秒?

相關問題