/**
* Defines a string (destinationAddress) for the phone number
* and gets the input text for the SMS message.
* Uses SmsManager.sendTextMessage to send the message.
* Before sending, checks to see if permission is granted.
*
* @param view View (message_icon) that was clicked.
*/
public void smsSendMessage(View view) {
EditText editText = (EditText) findViewById(R.id.editText_main);
// Set the destination phone number to the string in editText.
String destinationAddress = editText.getText().toString();
// Find the sms_message view.
EditText smsEditText = (EditText) findViewById(R.id.sms_message);
// Get the text of the sms message.
String smsMessage = smsEditText.getText().toString();
// Set the service center address if needed, otherwise null.
String scAddress = null;
// Set pending intents to broadcast
// when message sent and when delivered, or set to null.
PendingIntent sentIntent = null, deliveryIntent = null;
// Check for permission first.
checkForSmsPermission();
// Use SmsManager.
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(destinationAddress, scAddress, smsMessage,
sentIntent, deliveryIntent);
}
MainActivity.java 文件源码
java
阅读 23
收藏 0
点赞 0
评论 0
项目:android-fundamentals-phone-sms
作者:
评论列表
文章目录