The method that you led is based on reading HTTP headers. Specifically of this heading:
Content-Length: N
After reading the headers, you can discard the data itself, thus reducing the time to get the size of the response in bytes. This is the best way to determine "file size".
Another thing is that no server can be configured and in such a way that this header will not be included in the body of the server response, and it will not be possible to determine the file size in this way.
Your task can be solved even easier if you use the concept of hash sums. - If there is such an opportunity, use it - because downloading 32 bytes (average hash size) will be much less problematic than checking the file size. By the way, the size can remain the same if some values of bytes diverge, which means that the method of checking the integrity by size will fail, while the hash function will reflect any changes.
Small offtop:
Your exception is caused by the fact that Google is tired of hearing that "Android slows down." After all, the system itself is designed so that there are no brakes in it. None The problem is that inexperienced developers neglect many features, which leads to the appearance of bad applications in GP, causing the impression that "Android is slowing down." You just neglected one of these - the use of multithreading. The operation of accessing network resources is a priori long: set up a TCP handshake in three packets, and then transfer the array of data. Therefore, it is obviously forbidden to perform it in the UI thread.
NetworkOnMainThreadException. Call in the sameAsyncTask.doInBackgroundor where you download the file. - zRrronCreate. - zRrr