android发送短信指定收件人,android-发送短信给收件人

我正在编写一个应用程序,试图在该应用程序中向接收方发送短信,但是每当我单击发送时,都会收到消息:-短信发送失败,请稍后再试!

请看下面的屏幕截图,就像您看到的一样,在这里我正尝试向Rahul发送消息…

Manifest.xml:

请检查以下代码:

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();

}

}

});

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值