android发送短信指定收件人,android-发送短信给收件人
我正在編寫一個(gè)應(yīng)用程序,試圖在該應(yīng)用程序中向接收方發(fā)送短信,但是每當(dāng)我單擊發(fā)送時(shí),都會(huì)收到消息:-短信發(fā)送失敗,請(qǐng)稍后再試!
請(qǐng)看下面的屏幕截圖,就像您看到的一樣,在這里我正嘗試向Rahul發(fā)送消息…
Manifest.xml:
請(qǐng)檢查以下代碼:
private TextView name;
private ListView list;
private Database db;
private Contact contact;
Button buttonSend;
EditText textSMS;
private Map map = new LinkedHashMap();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.editor);
// bind GUI components
this.name = (TextView) findViewById(R.id.editor_name);
this.list = (ListView) findViewById(R.id.editor_list);
// check if contact id is valid
this.db = new Database(getContentResolver());
int contactId = getIntent().getIntExtra(CONTACT_ID, NO_CONTACT_ID);
this.contact = this.db.getContact(contactId);
if (this.contact == null) {
finish();
}
this.name.setText(this.contact.getName());
// pre-load information about all account types
AuthenticatorDescription[] authTypes = AccountManager.get(this).getAuthenticatorTypes();
for (AuthenticatorDescription authDesc : authTypes) {
this.map.put(authDesc.type, authDesc);
}
// bind list events
this.list.setOnItemClickListener(this);
this.list.setOnCreateContextMenuListener(this);
// create the GUI
updateView();
saveGreeting = (ImageButton) findViewById(R.id.greeting);
saveGreeting.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
customGreeting(v);
}
});
buttonSend = (Button) findViewById(R.id.buttonSend);
textSMS = (EditText) findViewById(R.id.editTextSMS);
buttonSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String recepient = name.getText().toString();
String sms = textSMS.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(recepient, 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();
}
}
});
}
總結(jié)
以上是生活随笔為你收集整理的android发送短信指定收件人,android-发送短信给收件人的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 树状数组c语言模板,【树状数组】Cows
- 下一篇: android4.0 菜单,Androi