public void sendDocument(Peer peer, String fullFilePath, String fileName) {

    int dot = fileName.indexOf('.');
    String mimeType = null;
    if (dot >= 0) {
      String ext = fileName.substring(dot + 1);
      mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
    }
    if (mimeType == null) {
      mimeType = "application/octet-stream";
    }

    Bitmap fastThumb = ImageHelper.loadOptimizedHQ(fullFilePath);
    if (fastThumb != null) {
      fastThumb = ImageHelper.scaleFit(fastThumb, 90, 90);
      byte[] fastThumbData = ImageHelper.save(fastThumb);
      sendDocument(
          peer,
          fileName,
          mimeType,
          new FastThumb(fastThumb.getWidth(), fastThumb.getHeight(), fastThumbData),
          fullFilePath);
    } else {
      sendDocument(peer, fileName, mimeType, fullFilePath);
    }
  }
  public void sendPhoto(Peer peer, String fullFilePath, String fileName) {
    try {
      Bitmap bmp = ImageHelper.loadOptimizedHQ(fullFilePath);
      if (bmp == null) {
        return;
      }
      Bitmap fastThumb = ImageHelper.scaleFit(bmp, 90, 90);

      String resultFileName = getExternalTempFile("image", "jpg");
      if (resultFileName == null) {
        return;
      }
      ImageHelper.save(bmp, resultFileName);

      byte[] fastThumbData = ImageHelper.save(fastThumb);

      sendPhoto(
          peer,
          fileName,
          bmp.getWidth(),
          bmp.getHeight(),
          new FastThumb(fastThumb.getWidth(), fastThumb.getHeight(), fastThumbData),
          resultFileName);
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }
  @Override
  public void changeMyAvatar(String descriptor) {
    try {
      Bitmap bmp = ImageHelper.loadOptimizedHQ(descriptor);
      if (bmp == null) {
        return;
      }
      String resultFileName = getExternalTempFile("image", "jpg");
      if (resultFileName == null) {
        return;
      }
      ImageHelper.save(bmp, resultFileName);

      super.changeMyAvatar(resultFileName);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  public void sendVideo(Peer peer, String fullFilePath, String fileName) {
    try {
      MediaMetadataRetriever retriever = new MediaMetadataRetriever();
      retriever.setDataSource(fullFilePath);
      int duration =
          (int)
              (Long.parseLong(
                      retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION))
                  / 1000L);
      Bitmap img = retriever.getFrameAtTime(0);
      int width = img.getWidth();
      int height = img.getHeight();
      Bitmap smallThumb = ImageHelper.scaleFit(img, 90, 90);
      byte[] smallThumbData = ImageHelper.save(smallThumb);

      FastThumb thumb =
          new FastThumb(smallThumb.getWidth(), smallThumb.getHeight(), smallThumbData);

      sendVideo(peer, fileName, width, height, duration, thumb, fullFilePath);
    } catch (Throwable e) {
      e.printStackTrace();
    }
  }