Example usage for android.telephony SmsManager downloadMultimediaMessage

List of usage examples for android.telephony SmsManager downloadMultimediaMessage

Introduction

In this page you can find the example usage for android.telephony SmsManager downloadMultimediaMessage.

Prototype

public void downloadMultimediaMessage(Context context, String locationUrl, Uri contentUri,
        Bundle configOverrides, PendingIntent downloadedIntent) 

Source Link

Document

Download an MMS message from carrier by a given location URL

Note: This method will never trigger an SMS disambiguation dialog.

Usage

From source file:com.android.mms.transaction.NotificationTransaction.java

public void run() {
    MmsLog.d(MmsApp.TXN_TAG, "NotificationTransaction: run");
    DownloadManager downloadManager = DownloadManager.getInstance();
    boolean autoDownload = allowAutoDownload(mContext, mSubId);
    try {// ww w.ja  va 2s.  c o m
        if (LOCAL_LOGV) {
            Log.v(TAG, "Notification transaction launched: " + this);
        }

        // By default, we set status to STATUS_DEFERRED because we
        // should response MMSC with STATUS_DEFERRED when we cannot
        // download a MM immediately.
        int status = STATUS_DEFERRED;
        // Don't try to download when data is suspended, as it will fail, so defer download
        if (!autoDownload) {
            // M: change API for ALPS01889178, use sub id.
            downloadManager.markState(mUri, DownloadManager.STATE_UNSTARTED, mSubId);
            sendNotifyRespInd(status);
            getState().setState(SUCCESS);
            getState().setContentUri(mUri);
            notifyObservers();
            return;
        }

        // M: change API for ALPS01889178, use sub id.
        downloadManager.markState(mUri, DownloadManager.STATE_DOWNLOADING, mSubId);

        if (mOpNotificationTransactionExt.run(mIsCancelling, mUri, mContext, getUri(), mContentLocation)) {
            mTransactionState.setState(TransactionState.SUCCESS);
            mTransactionState.setContentUri(mUri);
            mIsCancelling = false;
            return;
        }

        if (LOCAL_LOGV) {
            Log.v(TAG, "Content-Location: " + mContentLocation);
        }
        mPduFile = createPduFile(null, RETRIEVE_RESULT_NAME + mUri.getLastPathSegment());
        mPduFile.setWritable(true, false);

        //Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED);
        //intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
        //intent.putExtra(TransactionBundle.URI, mUri.toString());

        Log.d(MmsApp.TXN_TAG, "NotificationTransaction mUri:" + mUri);
        final Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED, mUri, mContext,
                MmsReceiver.class);
        intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);

        PendingIntent downloadedIntent = PendingIntent.getBroadcast(mContext, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        SmsManager manager = SmsManager.getSmsManagerForSubscriptionId(mSubId);
        Log.d(MmsApp.TXN_TAG, "download MMS with param, mContentLocation = " + mContentLocation + ", mUri = "
                + mUri + ", subId" + mSubId);

        /// M: Add MmsService configure param @{
        Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, mPduFile);
        manager.downloadMultimediaMessage(mContext, mContentLocation, pduFileUri,
                MmsConfig.getMmsServiceConfig(), downloadedIntent);
        /// @}

        // sendNotifyRespInd(status);

        // Make sure this thread isn't over the limits in message count.
        Recycler.getMmsRecycler().deleteOldMessagesInSameThreadAsMessage(mContext, mUri);
        MmsWidgetProvider.notifyDatasetChanged(mContext);
    } catch (Throwable t) {
        getState().setState(FAILED);
        getState().setContentUri(mUri);
        notifyObservers();
        Log.e(TAG, Log.getStackTraceString(t));
    }
}

From source file:com.android.mms.transaction.RetrieveTransaction.java

public void run() {
    MmsLog.i(MmsApp.TXN_TAG, "RetrieveTransaction: run()");
    try {/*from   www  . j a v  a2s  .  c o  m*/
        NotificationInd nInd = (NotificationInd) PduPersister.getPduPersister(mContext).load(mUri);
        if (nInd.getExpiry() < System.currentTimeMillis() / 1000L) {
            MmsLog.d(MmsApp.TXN_TAG, "The message is expired!");
            sendExpiredRes();
            // Change the downloading state of the M-Notification.ind.
            DownloadManager.getInstance().markState(mUri, DownloadManager.STATE_DOWNLOADING);
            mTransactionState.setState(TransactionState.SUCCESS);
            mTransactionState.setContentUri(mUri);
            notifyObservers();
            return;
        }

        // Change the downloading state of the M-Notification.ind.
        DownloadManager.getInstance().markState(mUri, DownloadManager.STATE_DOWNLOADING);

        /// M: For OP009, check if cancel download requested. @{
        /*            if (MmsConfig.isCancelDownloadEnable() && mIsCancelling) {
        mTransactionState.setState(TransactionState.SUCCESS);
        mTransactionState.setContentUri(mUri);
                
        if (MmsConfig.isCancelDownloadEnable()) {
            sMmsFailedNotifyPlugin.popupToast(mContext,
                IMmsFailedNotifyExt.CANCEL_DOWNLOAD, null);
        }
        mIsCancelling = false;
        final Uri trxnUri = getUri();
        sCancelDownloadPlugin.markStateExt(trxnUri, sCancelDownloadPlugin.STATE_COMPLETE);
        DownloadManager.getInstance().markState(trxnUri, DownloadManager.STATE_UNSTARTED);
                
        return;
                    }*/
        /// @}

        if (mOpRetrieveTransactionExt.run(mIsCancelling, mUri, mContext, getUri(), mContentLocation)) {
            mTransactionState.setState(TransactionState.SUCCESS);
            mTransactionState.setContentUri(mUri);
            mIsCancelling = false;
            return;
        }

        mPduFile = createPduFile(null, RETRIEVE_RESULT_NAME + mUri.getLastPathSegment());
        mPduFile.setWritable(true, false);
        //Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED);
        //intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
        //intent.putExtra(TransactionBundle.URI, mUri.toString());
        Log.d(MmsApp.TXN_TAG, "RetrieveTransaction mUri:" + mUri);
        final Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED, mUri, mContext,
                MmsReceiver.class);
        intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);

        PendingIntent downloadedIntent = PendingIntent.getBroadcast(mContext, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        SmsManager manager = SmsManager.getSmsManagerForSubscriptionId(mSubId);
        Log.d(MmsApp.TXN_TAG, "download MMS with param, mContentLocation = " + mContentLocation + ", mUri = "
                + mUri + ", subId" + mSubId);
        /// M: Add MmsService configure param @{
        Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, mPduFile);
        manager.downloadMultimediaMessage(mContext, mContentLocation, pduFileUri,
                MmsConfig.getMmsServiceConfig(), downloadedIntent);
        /// @}

        // Make sure this thread isn't over the limits in message count.
        Recycler.getMmsRecycler().deleteOldMessagesInSameThreadAsMessage(mContext, mUri);

        /// OP009 MMS Feature: cancel download Mms @{
        /*            if (MmsConfig.isCancelDownloadEnable()) {
        sCancelDownloadPlugin.addHttpClient(mContentLocation, mUri);
                    }*/
        /// @}

        // Send ACK to the Proxy-Relay to indicate we have fetched the
        // MM successfully.
        // Don't mark the transaction as failed if we failed to send it.
        // sendAcknowledgeInd(retrieveConf);
    } catch (Throwable t) {
        Log.e(TAG, Log.getStackTraceString(t));
        mTransactionState.setState(TransactionState.FAILED);
        mTransactionState.setContentUri(mUri);
        notifyObservers();
    }
}