@Override
  public void onReceiveFile(FileReceiver fileReceiver) {
    String fileName = fileReceiver.getFileTransferInfo().getFileName();
    String sendUserName = fileReceiver.getSendUser().getUserName();
    File file = null;
    long fileSize = fileReceiver.getFileTransferInfo().getFileSize();
    Log.d(TAG, "onReceiveFile:" + fileName + "," + sendUserName + ",size=" + fileSize);
    // define a file to save the receive file
    File fileDir = new File(DreamConstant.DREAMLINK_FOLDER);
    if (!fileDir.exists()) {
      fileDir.mkdirs();
    }

    String filePath = DreamConstant.DREAMLINK_FOLDER + File.separator + fileName;
    file = new File(filePath);
    if (!file.exists()) {
      try {
        file.createNewFile();
      } catch (IOException e) {
        Log.e(TAG, "create file error:" + e.toString());
        mNotice.showToast("can not create the file:" + fileName);
        return;
      }
    } else {
      // if file is exist,auto rename
      fileName = FileInfoManager.autoRename(fileName);
      while (new File(DreamConstant.DREAMLINK_FOLDER + File.separator + fileName).exists()) {
        fileName = FileInfoManager.autoRename(fileName);
      }
      filePath = DreamConstant.DREAMLINK_FOLDER + File.separator + fileName;
      file = new File(filePath);
    }

    HistoryInfo historyInfo = new HistoryInfo();
    historyInfo.setFile(file);
    historyInfo.setFileSize(fileSize);
    historyInfo.setSendUserName(sendUserName);
    historyInfo.setReceiveUser(mUserManager.getLocalUser());
    historyInfo.setMsgType(HistoryManager.TYPE_RECEIVE);
    historyInfo.setDate(System.currentTimeMillis());
    historyInfo.setStatus(HistoryManager.STATUS_PRE_RECEIVE);
    historyInfo = mFileInfoManager.getHistoryInfo(historyInfo);

    ContentValues values = mHistoryManager.getInsertValues(historyInfo);
    Uri uri = getContentResolver().insert(MetaData.History.CONTENT_URI, values);
    Object key = new Object();
    mTransferMap.put(key, uri);
    Log.d(TAG, "onReceiveFile.mTransferMap.size=" + mTransferMap.size());

    fileReceiver.receiveFile(file, FileTransferService.this, key);
  }
    private void addToSendQueue() {
      HistoryInfo historyInfo = new HistoryInfo();
      historyInfo.setFile(file);
      historyInfo.setFileSize(file.length());
      historyInfo.setReceiveUser(receiveUser);
      historyInfo.setSendUserName(getResources().getString(R.string.me));
      historyInfo.setMsgType(HistoryManager.TYPE_SEND);
      historyInfo.setDate(System.currentTimeMillis());
      historyInfo.setStatus(HistoryManager.STATUS_PRE_SEND);
      historyInfo = mFileInfoManager.getHistoryInfo(historyInfo);

      ContentValues values = mHistoryManager.getInsertValues(historyInfo);
      Uri uri = getContentResolver().insert(MetaData.History.CONTENT_URI, values);
      key = new Object();
      // save file & uri map
      mTransferMap.put(key, uri);
    }