From 22e0a2e9e8034f8c33cec704df178536f34d350b Mon Sep 17 00:00:00 2001 From: Philippe Date: Fri, 26 Feb 2021 15:55:15 -0500 Subject: [PATCH] Dispatching mms download success/failure with transactionId Change-Id: Icc2d54a4aac6e9ed2e1a448c9aece2d729405a02 --- .../send_message/MmsReceivedReceiver.java | 34 ++++++++++++++++--- .../MmsReceivedReceiverImpl.java | 4 +-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/library/src/main/java/com/klinker/android/send_message/MmsReceivedReceiver.java b/library/src/main/java/com/klinker/android/send_message/MmsReceivedReceiver.java index 06056a75..35a7528f 100644 --- a/library/src/main/java/com/klinker/android/send_message/MmsReceivedReceiver.java +++ b/library/src/main/java/com/klinker/android/send_message/MmsReceivedReceiver.java @@ -19,6 +19,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.database.Cursor; import android.net.Uri; import android.os.AsyncTask; import android.os.Build; @@ -71,8 +72,8 @@ public abstract class MmsReceivedReceiver extends BroadcastReceiver { private static final ExecutorService RECEIVE_NOTIFICATION_EXECUTOR = Executors.newSingleThreadExecutor(); - public abstract void onMessageReceived(Context context, Uri messageUri); - public abstract void onError(Context context, String error); + public abstract void onMessageReceived(Context context, Uri messageUri, String transactionId); + public abstract void onError(Context context, String error, String transactionId); public MmscInformation getMmscInfoForReceptionAck() { // Override this and provide the MMSC to send the ACK to. @@ -84,6 +85,28 @@ public MmscInformation getMmscInfoForReceptionAck() { return null; } + /** + * Retrieve the transaction id from the original incoming mms. + * PushReceiver removes the transaction id from the pdu table once mms is downloaded. If an application wants to map it to its internal database, this method is used + * to get the transaction id and dispatches the success/failure including it + * + * @param context + * @param locationUrl the locationUrl from the incoming mms + * @return + */ + private String getOriginalMmsTransactionId(Context context, String locationUrl) { + String transactionId = null; + Cursor cursor = SqliteWrapper.query(context, context.getContentResolver(), Telephony.Mms.CONTENT_URI, null, "m_type=? AND ct_l =?", new String[]{Integer.toString(130), locationUrl}, null); + + if (cursor != null) { + if (cursor.moveToNext()) { + transactionId = cursor.getString(cursor.getColumnIndex(Telephony.Mms.TRANSACTION_ID)); + } + } + + return transactionId; + } + @Override public final void onReceive(final Context context, final Intent intent) { Log.v(TAG, "MMS has finished downloading, persisting it to the database"); @@ -98,6 +121,7 @@ public void run() { FileInputStream reader = null; Uri messageUri = null; String errorMessage = null; + String originalTransactionId = getOriginalMmsTransactionId(context, intent.getStringExtra(EXTRA_LOCATION_URL)); try { File mDownloadFile = new File(path); @@ -142,12 +166,14 @@ public void run() { handleHttpError(context, intent); DownloadManager.finishDownload(intent.getStringExtra(EXTRA_LOCATION_URL)); + // Dispatches the information with original transaction id in order for application to retrieve it internally in case they are using an external database + // to store the messages if (messageUri != null) { - onMessageReceived(context, messageUri); + onMessageReceived(context, messageUri, originalTransactionId); } if (errorMessage != null) { - onError(context, errorMessage); + onError(context, errorMessage, originalTransactionId); } } }).start(); diff --git a/sample/src/main/java/com/klinker/android/messaging_sample/MmsReceivedReceiverImpl.java b/sample/src/main/java/com/klinker/android/messaging_sample/MmsReceivedReceiverImpl.java index 63275408..d271063e 100644 --- a/sample/src/main/java/com/klinker/android/messaging_sample/MmsReceivedReceiverImpl.java +++ b/sample/src/main/java/com/klinker/android/messaging_sample/MmsReceivedReceiverImpl.java @@ -9,12 +9,12 @@ public class MmsReceivedReceiverImpl extends MmsReceivedReceiver { @Override - public void onMessageReceived(Context context, Uri messageUri) { + public void onMessageReceived(Context context, Uri messageUri, String transactionId) { Log.v("MmsReceived", "message received: " + messageUri.toString()); } @Override - public void onError(Context context, String error) { + public void onError(Context context, String error, String transactionId) { Log.v("MmsReceived", "error: " + error); }