Q:

length shows minus in progress bar

I am downloading a video from a URL, when I am trying to get the progress it shows minus value, at below I have added my code,
byte[] buffer = new byte[1024];
int len1 = 0;
long total = 0;
while ((len1 = is.read(buffer)) != -1) {
    if (cancelDialogStatus) {
        break;
    }
    Log.e("System out", "doInBackground: progress:::" + len1);
    total += len1;
    // publishing the progress....
    // After this onProgressUpdate will be called
    int prg = (int) ((total * 100) / lenghtOfFile);
    Log.d("System out", "doInBackground: progress:::" + prg);
    if (prg > 100) {
        publishProgress(""
                + 100);
        fos.write(buffer, 0, len1);
        break;
    } else {
        publishProgress(""
                + (int) ((total * 100) / lenghtOfFile));
        fos.write(buffer, 0, len1);
    }
}

A:

It is basically due to the Content-Length header parameter not being set by the server. Like when you download from Gdrive it doesn't show total file size while the download is in progress. 
The simple answer is that the content length is not known. Or more specifically, the server is not setting a Content-Length header in the response message.
The detailed solution is described here.

