Ejemplo n.º 1
0
  private void initActions() {
    if (Utils.isDefaultSmsApp(this)) {
      setDefaultAppButton.setVisibility(View.GONE);
    } else {
      setDefaultAppButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              setDefaultSmsApp();
            }
          });
    }

    selectApns.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            initApns();
          }
        });

    fromField.setText(Utils.getMyPhoneNumber(this));
    toField.setText(Utils.getMyPhoneNumber(this));

    imageToSend.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            toggleSendImage();
          }
        });

    sendButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            sendMessage();
          }
        });

    log.setHasFixedSize(false);
    log.setLayoutManager(new LinearLayoutManager(this));
    logAdapter = new LogAdapter(new ArrayList<String>());
    log.setAdapter(logAdapter);
  }
  public void run() {
    PduPersister persister = PduPersister.getPduPersister(mContext);

    try {
      // Load M-read-rec.ind from outbox
      ReadRecInd readRecInd = (ReadRecInd) persister.load(mReadReportURI);

      // insert the 'from' address per spec
      String lineNumber = Utils.getMyPhoneNumber(mContext);
      readRecInd.setFrom(new EncodedStringValue(lineNumber));

      // Pack M-read-rec.ind and send it
      byte[] postingData = new PduComposer(mContext, readRecInd).make();
      sendPdu(postingData);

      Uri uri = persister.move(mReadReportURI, Uri.parse("content://mms/sent"));
      mTransactionState.setState(TransactionState.SUCCESS);
      mTransactionState.setContentUri(uri);
    } catch (IOException e) {
      if (LOCAL_LOGV) {
        Log.v(TAG, "Failed to send M-Read-Rec.Ind.", e);
      }
    } catch (MmsException e) {
      if (LOCAL_LOGV) {
        Log.v(TAG, "Failed to load message from Outbox.", e);
      }
    } catch (RuntimeException e) {
      if (LOCAL_LOGV) {
        Log.e(TAG, "Unexpected RuntimeException.", e);
      }
    } finally {
      if (mTransactionState.getState() != TransactionState.SUCCESS) {
        mTransactionState.setState(TransactionState.FAILED);
        mTransactionState.setContentUri(mReadReportURI);
      }
      notifyObservers();
    }
  }