login about faq

Currently use ftp by follow sample https://www.example-code.com/android/ftp_download_with_progress.asp. It's works fine. But on Android 6.0 CkFtp2Progress callbacks not fire. I'm confused. Help me please. Some piece of code

public void loadFile(final int position, final Config.File file, final OnDownloadFileListener listener, final OnDownloadingProgressListener progressListener) {

asyncManager.runAsync(new Runnable() {

@Override

public void run() {

if(file == null || file.file == null) { sendError("", listener); return; }

            CkFtp2 ftp = getFtpClient();
            CustomProgressWatcher progressWatcher = new CustomProgressWatcher(position, file.size
                    , progressListener);
            ftp.put_EventCallbackObject(progressWatcher);

            //  Connect and login to the FTP server.
            boolean success = ftp.ConnectOnly();
            if (!success) {
                sendError(ftp.lastErrorText(), listener);
                return;
            }

            success = ftp.LoginAfterConnectOnly();
            if (!success) {
                sendError(ftp.lastErrorText(), listener);
                ftp.Disconnect();
                return;
            }

            String localFilename = fileNameProvider.getLocalStorageFileName(file);
            String remoteFilename = fileNameProvider.getRemoteFileName(file);

            //  Change to the remote directory where the file is located.
            //  This step is only necessary if the file is not in the root directory
            //  for the FTP account.
            success = ftp.ChangeRemoteDir("remoteDirName");
            if (!success) {
                L.e(ftp.lastErrorText());
                ftp.Disconnect();
                return;
            }

            //  Download the file.
            success = ftp.GetFile(remoteFilename,localFilename);
            if (!success) {
                sendError(ftp.lastErrorText(), listener);
                ftp.Disconnect();
                return;
            } else {
                L.e("File Downloaded = " + file.file);
            }

            DownloadResult result = new DownloadResult();
            result.result = file;
            sendResult(result, listener);

            ftp.put_EventCallbackObject(null);
            ftp.Disconnect();
        }
    });
}

private CkFtp2 getFtpClient() {
    CkFtp2 ftp = new CkFtp2();
    ftp.put_Hostname(CommonConfig.BASE_URL);
    ftp.put_Username(CommonConfig.USER_NAME);
    ftp.put_Password(CommonConfig.USER_PASSWORD);

    ftp.put_HeartbeatMs(300);

    ftp.put_CrlfMode(2);
    ftp.put_PreferIpv6(true);
    ftp.put_AuthTls(true);
    ftp.put_Passive(true);

    return ftp;
}

public class CustomProgressWatcher extends CkFtp2Progress {

private FTPDownloadManagerImpl.OnDownloadingProgressListener listener;
private int position;
private long onePercent;
private long lastByteCount = 0l;

public CustomProgressWatcher(int position, long fileSize,
                             FTPDownloadManagerImpl.OnDownloadingProgressListener listener) {
    this.position = position;
    this.listener = listener;
    onePercent = fileSize / 100;
}

@Override
public void DownloadRate(final long byteCount, long bytesPerSec) {
    super.DownloadRate(byteCount, bytesPerSec);
    final long completion = byteCount / onePercent;
    final long byteTransfered = byteCount - lastByteCount;
    lastByteCount = byteCount;

    L.e("byteCount = " + byteCount);
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            if (listener != null) {
                listener.onProgress(completion, position);
                listener.onByteCount(byteTransfered);
            }
        }
    });
}

}

asked Jul 20 at 03:02

Dgr's gravatar image

Dgr
11

edited Jul 20 at 03:20


I'll have a look as soon as possible..

link

answered Jul 20 at 10:54

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Please give this new build a try: http://www.chilkatsoft.com/download/preRelease/chilkat-9.5.0-android.zip

I tested it, and everything seems to be working. Also.. to be sure events are working and it's not just a problem with DownloadRate (or the code within your DownloadRate handler), add a method for ProgressInfo to see if you get those events. For example:

public class CustomProgressWatcher extends CkFtp2Progress {
...
  public void ProgressInfo(String name, String value)
    {
    ...
    return;
    }
};
link

answered Jul 20 at 19:20

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×4

Asked: Jul 20 at 03:02

Seen: 230 times

Last updated: Jul 20 at 19:20

powered by OSQA