Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatching mms download success/failure with transactionId #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down