欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SimpleCommand實(shí)現(xiàn)上傳文件或視頻功能(四)

 更新時(shí)間:2017年10月20日 10:21:42   作者:Danny_姜  
這篇文章主要介紹了SimpleCommand實(shí)現(xiàn)上傳文件或視頻功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

上傳文件的核心功能主要是在UploadCommand.java中實(shí)現(xiàn)

使用步驟:

1 創(chuàng)建UploadCommand的構(gòu)建類(lèi)Builder

UploadCommand.Builder builder = new UploadCommand.Builder();

2 通過(guò)構(gòu)建類(lèi)設(shè)置UploadCommand的各種屬性

builder.domain("上傳地址的域名")
        .path("上傳接口")
        .contentType("請(qǐng)求頭文件的Content-type")
        .mediaType(Params.Body.MEDIA_TYPE_VIDEO)
        .file("上傳文件的絕對(duì)路徑")
        .transferListener(new SimpleRequestBody.ProgressListener() { // 上傳進(jìn)度的監(jiān)聽(tīng)器
          @Override
          public void onDataTransferred(long transferred, long contentLength) {
            Log.e("TAG", "already transfer " + 100 * ((double) transferred / (double) contentLength));
          }
 });


3 通過(guò)構(gòu)建類(lèi)構(gòu)造UploadCommand對(duì)象,并啟動(dòng)

UploadCommand uploadCommand = builder.build();
uploadCommand.start(this, new AppResultReceiver(new Handler(), MainActivity.this));

注意:以上代碼需要將MainActivity實(shí)現(xiàn)AppResultReceiver.ResultListener接口

4 在onResultSuccess方法中,區(qū)分是否是UploadCommand,并解析數(shù)據(jù)

@Override
  public void onResultSuccess(Bundle resultData) {
    if (null != resultData) {
      if (UploadCommand.UPLOAD_CMD.equals(
          resultData.getString(Params.CommandMessage.CMD_CODE))) {
        Logger.e("JIANG", "上傳成功");
      }
    }
  }

框架github地址: SimpleCommand框架

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論