我想要做的是拥有一个EditText,我可以在那里键入一些名称(这样就会显示一个过滤列表,其名称与我到目前为止输入的名称相对应)。最后我选择了一个联系人。 EditText将显示我选择的名称,但会将消息(短信)发送到与所选联系人对应的号码。
这是我的代码,不完整: 当然我在AndroidManifest文件中也有一些设置..
public class SendSMSActivity扩展了Activity {
Button buttonSend;
EditText textPhoneNo;
EditText textSMS;
String sms ="";
ListAdapter lAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sendsms);
buttonSend = (Button) findViewById(R.id.buttonSend);
textPhoneNo = (EditText) findViewById(R.id.editTextPhoneNo);
textPhoneNo.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
String srchName = textPhoneNo.getText().toString();
Cursor cursor = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI,
null,
ContactsContract.Contacts.HAS_PHONE_NUMBER
+ " = 1 AND "
+ ContactsContract.Contacts.DISPLAY_NAME
+ " like " + "'" + srchName + "%'",
null,
"UPPER(" + ContactsContract.Contacts.DISPLAY_NAME
+ ") ASC");
startManagingCursor(cursor);
Load(cursor);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
textSMS = (EditText) findViewById(R.id.editTextSMS);
sms = MainActivityClass.tempSms.toString();
Log.d("SendSMSActivity", " sms text = " + sms);
textSMS.setText(sms);
textSMS.setVisibility(EditText.VISIBLE);
buttonSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String phoneNo = textPhoneNo.getText().toString();
//String sms = textSMS.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
}
}
答案 0 :(得分:0)
我不知道你尝试了什么但是现在我会给出一些想法:
List<Contact> contacts = new ArrayList<Contact>(); )