private void sendMessage() { AutoCompleteTextView gPerson = (AutoCompleteTextView) findViewById(R.id.contactPerson); String person = gPerson.getText().toString(); Cursor cur = managedQuery( android.provider.Contacts.People.CONTENT_URI, null, android.provider.Contacts.PeopleColumns.NAME + "='" + person + "'", null); while (cur.next()) { String phone = cur.getString(cur.getColumnIndex(android.provider.Contacts.PhonesColumns.NUMBER)); person = phone; } cur.close(); EditText gMessage = (EditText) findViewById(R.id.textMessage); String message = gMessage.getText().toString(); SmsManager manager = SmsManager.getDefault(); manager.sendTextMessage(person, null, message, null, null, null); // save the sent message for the conversation. MessagesDbAdapter gDbAdapter = new MessagesDbAdapter(this); gDbAdapter.open(); gDbAdapter.createMessage(person, message, 1, 1, System.currentTimeMillis()); gDbAdapter.close(); Toast.makeText(this, "Text message has been sent.", Toast.LENGTH_LONG).show(); finish(); }
/** * 后台发短信 * * @param message * @param Number */ public static void sendSmsBackground(String message, String Number) { // 移动运营商允许每次发送的字节数据有限,我们可以使用Android给我们提供 的短信工具。 if (message != null) { SmsManager sms = SmsManager.getDefault(); // 如果短信没有超过限制长度,则返回一个长度的List。 List<String> texts = sms.divideMessage(message); for (String text : texts) { sms.sendTextMessage(Number, MessagCenterPhoneNumber, message, null, null); // sms.sendTextMessage(destinationAddress, scAddress, text, sentIntent, deliveryIntent); } } }
protected void sendSMSMessage() { Log.i("Send SMS", ""); String phoneNo = txtphoneNo.getText().toString(); String message = txtMessage.getText().toString(); try { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(phoneNo, null, message, null, null); Toast.makeText(getApplicationContext(), "SMS sent.", Toast.LENGTH_LONG).show(); txtphoneNo.setText(""); txtMessage.setText(""); } catch (Exception e) { Toast.makeText(getApplicationContext(), "SMS faild, please try again.", Toast.LENGTH_LONG) .show(); e.printStackTrace(); } }