/** * Called when a status report is received. This should correspond to a previously successful * SEND. * * @param ar AsyncResult passed into the message handler. ar.result should be a String * representing the status report PDU, as ASCII hex. */ protected void handleStatusReport(AsyncResult ar) { String pduString = (String) ar.result; SmsMessage sms = SmsMessage.newFromCDS(pduString); if (sms != null) { int tpStatus = sms.getStatus(); int messageRef = sms.messageRef; for (int i = 0, count = deliveryPendingList.size(); i < count; i++) { SmsTracker tracker = deliveryPendingList.get(i); if (tracker.mMessageRef == messageRef) { // Found it. Remove from list and broadcast. if (tpStatus >= Sms.STATUS_FAILED || tpStatus < Sms.STATUS_PENDING) { deliveryPendingList.remove(i); } PendingIntent intent = tracker.mDeliveryIntent; Intent fillIn = new Intent(); fillIn.putExtra("pdu", IccUtils.hexStringToBytes(pduString)); try { intent.send(mContext, Activity.RESULT_OK, fillIn); } catch (CanceledException ex) { } // Only expect to see one tracker matching this messageref break; } } } acknowledgeLastIncomingSms(true, Intents.RESULT_SMS_HANDLED, null); }
private void handleDeliveredMessage(Intent intent) { long messageId = intent.getLongExtra("message_id", -1); byte[] pdu = intent.getByteArrayExtra("pdu"); SmsMessage message = SmsMessage.createFromPdu(pdu); if (message == null) { return; } DatabaseFactory.getSmsDatabase(context).markStatus(messageId, message.getStatus()); }
private boolean updateMessageStatus(Context context, Uri messageUri, byte[] pdu) { // Create a "status/#" URL and use it to update the // message's status in the database. boolean isStatusReport = false; Cursor cursor = SqliteWrapper.query( context, context.getContentResolver(), messageUri, ID_PROJECTION, null, null, null); try { if (cursor.moveToFirst()) { int messageId = cursor.getInt(0); Uri updateUri = ContentUris.withAppendedId(STATUS_URI, messageId); SmsMessage message = SmsMessage.createFromPdu(pdu); int status = message.getStatus(); isStatusReport = message.isStatusReportMessage(); ContentValues contentValues = new ContentValues(1); if (Log.isLoggable(LogTag.TAG, Log.DEBUG)) { log( "updateMessageStatus: msgUrl=" + messageUri + ", status=" + status + ", isStatusReport=" + isStatusReport); } contentValues.put(Sms.STATUS, status); SqliteWrapper.update( context, context.getContentResolver(), updateUri, contentValues, null, null); } else { error("Can't find message for status update: " + messageUri); } } finally { cursor.close(); } return isStatusReport; }