FileDocCategorySizeDatePackage
SmsMessageSender.javaAPI DocAndroid 1.5 API6806Wed May 06 22:42:46 BST 2009com.android.mms.transaction

SmsMessageSender

public class SmsMessageSender extends Object implements MessageSender

Fields Summary
private final android.content.Context
mContext
private final int
mNumberOfDests
private final String[]
mDests
private final String
mMessageText
private final String
mServiceCenter
private final long
mThreadId
private long
mTimestamp
private static final boolean
DEFAULT_DELIVERY_REPORT_MODE
private static final String[]
SERVICE_CENTER_PROJECTION
private static final String[]
DATE_PROJECTION
private static final int
COLUMN_REPLY_PATH_PRESENT
private static final int
COLUMN_SERVICE_CENTER
Constructors Summary
public SmsMessageSender(android.content.Context context, String[] dests, String msgText, long threadId)


          
              
        mContext = context;
        mMessageText = msgText;
        mNumberOfDests = dests.length;
        mDests = new String[mNumberOfDests];
        System.arraycopy(dests, 0, mDests, 0, mNumberOfDests);
        mTimestamp = System.currentTimeMillis();
        mThreadId = threadId > 0 ? threadId
                        : Threads.getOrCreateThreadId(context,
                                    new HashSet<String>(Arrays.asList(dests)));
        mServiceCenter = getOutgoingServiceCenter(mThreadId);
    
Methods Summary
private java.lang.StringgetOutgoingServiceCenter(long threadId)
Get the service center to use for a reply. The rule from TS 23.040 D.6 is that we send reply messages to the service center of the message to which we're replying, but only if we haven't already replied to that message and only if TP-Reply-Path was set in that message. Therefore, return the service center from the most recent message in the conversation, but only if it is a message from the other party, and only if TP-Reply-Path is set. Otherwise, return null.

        Cursor cursor = null;

        try {
            cursor = SqliteWrapper.query(mContext, mContext.getContentResolver(),
                            Sms.CONTENT_URI, SERVICE_CENTER_PROJECTION,
                            "thread_id = " + threadId, null, "date DESC");

            if ((cursor == null) || !cursor.moveToFirst()) {
                return null;
            }

            boolean replyPathPresent = (1 == cursor.getInt(COLUMN_REPLY_PATH_PRESENT));
            return replyPathPresent ? cursor.getString(COLUMN_SERVICE_CENTER) : null;
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    
public booleansendMessage(long token)

        if ((mMessageText == null) || (mNumberOfDests == 0)) {
            // Don't try to send an empty message.
            throw new MmsException("Null message body or dest.");
        }

        SmsManager smsManager = SmsManager.getDefault();

        for (int i = 0; i < mNumberOfDests; i++) {
            ArrayList<String> messages = smsManager.divideMessage(mMessageText);
            int messageCount = messages.size();
            ArrayList<PendingIntent> deliveryIntents =
                    new ArrayList<PendingIntent>(messageCount);
            ArrayList<PendingIntent> sentIntents =
                    new ArrayList<PendingIntent>(messageCount);
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
            boolean requestDeliveryReport = prefs.getBoolean(
                    MessagingPreferenceActivity.SMS_DELIVERY_REPORT_MODE,
                    DEFAULT_DELIVERY_REPORT_MODE);
            Uri uri = null;
            try {
                uri = Sms.Outbox.addMessage(mContext.getContentResolver(), mDests[i],
                            mMessageText, null, mTimestamp, requestDeliveryReport, mThreadId);
            } catch (SQLiteException e) {
                SqliteWrapper.checkSQLiteException(mContext, e);
            }

            for (int j = 0; j < messageCount; j++) {
                if (requestDeliveryReport) {
                    // TODO: Fix: It should not be necessary to
                    // specify the class in this intent.  Doing that
                    // unnecessarily limits customizability.
                    deliveryIntents.add(PendingIntent.getBroadcast(
                            mContext, 0,
                            new Intent(
                                    MessageStatusReceiver.MESSAGE_STATUS_RECEIVED_ACTION,
                                    uri,
                                    mContext,
                                    MessageStatusReceiver.class),
                            0));
                }
                sentIntents.add(PendingIntent.getBroadcast(
                        mContext, 0,
                        new Intent(SmsReceiverService.MESSAGE_SENT_ACTION,
                                uri,
                                mContext,
                                SmsReceiver.class),
                        0));
            }
            smsManager.sendMultipartTextMessage(
                    mDests[i], mServiceCenter, messages, sentIntents,
                    deliveryIntents);
        }
        return false;