package com.chicagoandroid.w160; import android.app.PendingIntent; import android.content.Context; import android.telephony.PhoneNumberUtils; import android.telephony.SmsManager; import android.util.Log; import android.widget.Toast; public class SmsSender { private static final String CLASS_NAME = SmsSender.class.getSimpleName(); public static void validateAndSendSms(Context context, String destinationAddress, String text) { if (!PhoneNumberUtils.isWellFormedSmsAddress(destinationAddress)) { Log.w(CLASS_NAME, "isWellFormedSmsAddress FALSE"); Toast.makeText(context, "DEstination address is malformed: " + destinationAddress, Toast.LENGTH_LONG).show(); return; } PendingIntent sentIntent = Main.pendingIntent; SmsManager smsManager = SmsManager.getDefault(); String scAddress = null; // service center address PendingIntent deliveryIntent = null; // broadcast when delivered smsManager.sendTextMessage(destinationAddress, scAddress, text, sentIntent, deliveryIntent); Log.w(CLASS_NAME, "message sent: " + text + " to " + destinationAddress); if (context != null) Toast.makeText(context, "Message sent to " + destinationAddress, Toast.LENGTH_SHORT).show(); } } |


