美文网首页
手动下载彩信

手动下载彩信

作者: 坠叶飘香 | 来源:发表于2019-05-26 17:03 被阅读0次
下载彩信.png 手动下载彩信

1.给下载按钮设置点击事件

packages\apps\Mms\src\com\android\mms\ui\MessageListItem.java

mDownloadButton.setOnClickListener(new OnClickListener() {
  @Override
  public void onClick(View v) {
    mDownloadingLabel.setVisibility(View.VISIBLE);
    mDownloadButton.setVisibility(View.GONE);
    Intent intent = new Intent(mContext, TransactionService.class);
    intent.putExtra(TransactionBundle.URI, mMessageItem.mMessageUri.toString());
    intent.putExtra(TransactionBundle.TRANSACTION_TYPE, Transaction.RETRIEVE_TRANSACTION);
    mContext.startService(intent);

    DownloadManager.getInstance().markState(mMessageItem.mMessageUri, DownloadManager.STATE_PRE_DOWNLOADING);
  }
});

2.onStartCommand

packages\apps\Mms\src\com\android\mms\transaction\TransactionService.java

public int onStartCommand(Intent intent, int flags, int startId) {
  if (intent != null) {
    Message msg = mServiceHandler.obtainMessage(EVENT_NEW_INTENT);
    msg.arg1 = startId;
    msg.obj = intent;
    mServiceHandler.sendMessage(msg);
  }
  return Service.START_NOT_STICKY;
}

3.handleMessage

EVENT_NEW_INTENT
packages\apps\Mms\src\com\android\mms\transaction\TransactionService.java

private final class ServiceHandler extends Handler {
  public void handleMessage(Message msg) {
    Transaction transaction = null;
    switch (msg.what) {
      case EVENT_NEW_INTENT:
        onNewIntent((Intent)msg.obj, msg.arg1);
        break;
    }
  }
}

4.onNewIntent

packages\apps\Mms\src\com\android\mms\transaction\TransactionService.java

public void onNewIntent(Intent intent, int serviceId) {
  if (ACTION_ONALARM.equals(action) || ACTION_ENABLE_AUTO_RETRIEVE.equals(action) ||
                (intent.getExtras() == null)) {
    
  } else{
    TransactionBundle args = new TransactionBundle(intent.getExtras());
    launchTransaction(serviceId, args, noNetwork);
  }
}

5.launchTransaction

packages\apps\Mms\src\com\android\mms\transaction\TransactionService.java

private void launchTransaction(int serviceId, TransactionBundle txnBundle, boolean noNetwork) {
  if (noNetwork) {
    Log.w(TAG, "launchTransaction: no network error!");
    onNetworkUnavailable(serviceId, txnBundle.getTransactionType());
    return;
  }
  Message msg = mServiceHandler.obtainMessage(EVENT_TRANSACTION_REQUEST);
  msg.arg1 = serviceId;
  msg.obj = txnBundle;

  mServiceHandler.sendMessage(msg);
}

6.handleMessage

EVENT_TRANSACTION_REQUEST
packages\apps\Mms\src\com\android\mms\transaction\TransactionService.java
private final class ServiceHandler extends Handler {
public void handleMessage(Message msg) {
Transaction transaction = null;
switch (msg.what) {
case EVENT_TRANSACTION_REQUEST:
int serviceId = msg.arg1;
try {
switch (transactionType) {
case Transaction.RETRIEVE_TRANSACTION:
transaction = new RetrieveTransaction(TransactionService.this, serviceId,transactionSettings, args.getUri());
break;
}

      if (!processTransaction(transaction)) {
        transaction = null;
        return;
      }
    } finally{
      if (transaction == null) {
        endMmsConnectivity();
        stopSelf(serviceId);
      }
    }
    return;
}

}
}

7.processTransaction

packages\apps\Mms\src\com\android\mms\transaction\TransactionService.java

private boolean processTransaction(Transaction transaction) throws IOException {
  transaction.attach(TransactionService.this);
  transaction.process();
}

8.process

packages\apps\Mms\src\com\android\mms\transaction\RetrieveTransaction.java

public void process() {
  new Thread(this, "RetrieveTransaction").start();
}

9.run

packages\apps\Mms\src\com\android\mms\transaction\RetrieveTransaction.java

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

    // Send GET request to MMSC and retrieve the response data.
    //下载彩信
    byte[] resp = getPdu(mContentLocation);

    // Parse M-Retrieve.conf
    RetrieveConf retrieveConf = (RetrieveConf) new PduParser(resp, PduParserUtil.shouldParseContentDisposition()).parse();

    // Store M-Retrieve.conf into Inbox
    //下载的彩信存入数据库
    PduPersister persister = PduPersister.getPduPersister(mContext);
    msgUri = persister.persist(retrieveConf, Inbox.CONTENT_URI, true,
                        MessagingPreferenceActivity.getIsGroupMmsEnabled(mContext), null);

    // Delete the corresponding M-Notification.ind.
    //删除通知
    SqliteWrapper.delete(mContext, mContext.getContentResolver(), mUri, null, null);

    sendAcknowledgeInd(retrieveConf);  //M-Acknowledge.ind
  } finally {
    if (mTransactionState.getState() != TransactionState.SUCCESS) {
      mTransactionState.setState(TransactionState.FAILED);
      mTransactionState.setContentUri(mUri);
      Log.e(TAG, "Retrieval failed.");
    }
    notifyObservers();
  }
}

10.sendAcknowledgeInd

packages\apps\Mms\src\com\android\mms\transaction\RetrieveTransaction.java

private void sendAcknowledgeInd(RetrieveConf rc) throws MmsException, IOException {
  // Send M-Acknowledge.ind to MMSC if required.
  // If the Transaction-ID isn't set in the M-Retrieve.conf, it means
  // the MMS proxy-relay doesn't require an ACK.
  byte[] tranId = rc.getTransactionId();
  if (tranId != null) {
    // Create M-Acknowledge.ind
    AcknowledgeInd acknowledgeInd = new AcknowledgeInd(
    PduHeaders.CURRENT_MMS_VERSION, tranId);

    // insert the 'from' address per spec
    String lineNumber = MessageUtils.getLocalNumber();
    acknowledgeInd.setFrom(new EncodedStringValue(lineNumber));

    // Pack M-Acknowledge.ind and send it
    if(MmsConfig.getNotifyWapMMSC()) {
      sendPdu(new PduComposer(mContext, acknowledgeInd).make(), mContentLocation);
    } else {
      sendPdu(new PduComposer(mContext, acknowledgeInd).make());
    }
  }
}

相关文章

  • 手动下载彩信

    1.给下载按钮设置点击事件 packages\apps\Mms\src\com\android\mms\ui\Me...

  • 申请来的诈骗

    手机上收到一个彩信 WIFI过去,5G马上普及了 居然收到彩信了 ———— 打开,下载 彩信消失了 取而代之的是,...

  • 收到彩信二

    收到通知,返回通知确认 下载彩信 1.onReceive packages\apps\Mms\src\com\an...

  • 提取按钮方式二

    前言:不能通过“自动提取按钮”软件自动发送彩信的,“安装手动提取按钮”并配合以下方法。 一、adb免安装,直接电脑...

  • Docker 安装

    一、 macOS 安装 Docker 手动下载安装 如果需要手动下载,可以通过这个链接下载:https://dow...

  • AndroidStudio 报错:Failed to open

    手动下载对应Gradle(AndroidStudio Gradle手动下载) 编译报错: 原因 一般是因为项目所需...

  • 手动下载Gradle

    1. 到网站上下载相应的Gradle版本: http://www.androiddevtools.cn http:...

  • 1、 jvm-sandbox-repeater 安装

    1、手动下载sandbox-1.3.3-bin.tar 下载后,手动解压至当前用户的家目录下 2、下载jvm-sa...

  • 彩信

    彩信的英文名是MMS,它是MultimediaMessagingService的缩写,意为多媒体信息服务。最大的特...

  • 彩信

    下午六点多,意外地收到一则彩信,是一只黄色的蝴蝶,趴在做了防滑处理的“地板上”上。 那个电话号码似曾相识,却又想不...

网友评论

      本文标题:手动下载彩信

      本文链接:https://www.haomeiwen.com/subject/ofcftctx.html