Exemple #1
0
 private static Uri writePduToTempFile(final Context context, final GenericPdu pdu, int subId)
     throws MmsFailureException {
   final Uri contentUri = MmsFileProvider.buildRawMmsUri();
   final File tempFile = MmsFileProvider.getFile(contentUri);
   FileOutputStream writer = null;
   try {
     // Ensure rawmms directory exists
     tempFile.getParentFile().mkdirs();
     writer = new FileOutputStream(tempFile);
     final byte[] pduBytes = new PduComposer(context, pdu).make();
     if (pduBytes == null) {
       throw new MmsFailureException(MmsUtils.MMS_REQUEST_NO_RETRY, "Failed to compose PDU");
     }
     if (pduBytes.length > MmsConfig.get(subId).getMaxMessageSize()) {
       throw new MmsFailureException(
           MmsUtils.MMS_REQUEST_NO_RETRY, MessageData.RAW_TELEPHONY_STATUS_MESSAGE_TOO_BIG);
     }
     writer.write(pduBytes);
   } catch (final IOException e) {
     if (tempFile != null) {
       tempFile.delete();
     }
     LogUtil.e(TAG, "Cannot create temporary file " + tempFile.getAbsolutePath(), e);
     throw new MmsFailureException(MmsUtils.MMS_REQUEST_AUTO_RETRY, "Cannot create raw mms file");
   } catch (final OutOfMemoryError e) {
     if (tempFile != null) {
       tempFile.delete();
     }
     LogUtil.e(TAG, "Out of memory in composing PDU", e);
     throw new MmsFailureException(
         MmsUtils.MMS_REQUEST_MANUAL_RETRY, MessageData.RAW_TELEPHONY_STATUS_MESSAGE_TOO_BIG);
   } finally {
     if (writer != null) {
       try {
         writer.close();
       } catch (final IOException e) {
         // no action we can take here
       }
     }
   }
   return contentUri;
 }
Exemple #2
0
  /**
   * Download an MMS message.
   *
   * @param context Context
   * @param contentLocation The url of the MMS message
   * @throws MmsFailureException
   * @throws InvalidHeaderValueException
   */
  public static void downloadMms(
      final Context context, final int subId, final String contentLocation, Bundle extras)
      throws MmsFailureException, InvalidHeaderValueException {
    final Uri requestUri = Uri.parse(contentLocation);
    final Uri contentUri = MmsFileProvider.buildRawMmsUri();

    final Intent downloadedIntent =
        new Intent(
            SendStatusReceiver.MMS_DOWNLOADED_ACTION,
            requestUri,
            context,
            SendStatusReceiver.class);
    downloadedIntent.putExtra(SendMessageAction.EXTRA_CONTENT_URI, contentUri);
    if (extras != null) {
      downloadedIntent.putExtras(extras);
    }
    final PendingIntent downloadedPendingIntent =
        PendingIntent.getBroadcast(
            context, 0 /*request code*/, downloadedIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    MmsManager.downloadMultimediaMessage(
        subId, context, contentLocation, contentUri, downloadedPendingIntent);
  }