我正在编写一个应用程序,试图在该应用程序中向接收方发送短信,但是每当我单击发送时,都会收到消息:-短信发送失败,请稍后再试!
请看下面的屏幕截图,就像您看到的一样,在这里我正尝试向Rahul发送消息…
Manifest.xml:
<uses-permission androID:name="androID.permission.SEND_SMS" />
请检查以下代码:
private TextVIEw name;private ListVIEw List;private Database db;private Contact contact;button buttonSend;EditText textSMS;private Map<String, AuthenticatorDescription> map = new linkedHashMap<String, AuthenticatorDescription>();@OverrIDeprotected 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(); } } });}
解决方法:
阿米特
告诉我你在哪里检查
在模拟器中,短信不会发送
仅在实际设备中发送
请检查以下提到的链接
它正常工作
1)http://mobiforge.com/developing/story/sms-messaging-android
2)http://katharnavas.wordpress.com/2009/10/07/how-to-send-sms-from-android-programatically/
3)http://saga-androidapplication.blogspot.in/2011/06/how-to-send-and-receive-message-using.html
4)http://www.java-samples.com/showtutorial.php?tutorialid=1540
5)http://codeoncloud.blogspot.in/2012/06/send-sms-from-android-application.html
让我告诉您您是否仍然遇到任何问题
总结以上是内存溢出为你收集整理的android-发送短信给收件人全部内容,希望文章能够帮你解决android-发送短信给收件人所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)