Get file size from url

Viewed 10421

I having a problem with this URL url its a 302 url and it redirects to this site when you run in brwoser http://mp3goo.io/ but when you post this on a download manager it shows 10 mb file and i downloaded and worked fine. And i checked with my android code it says -1 content length how to get the file size like download manager image

2 Answers

That will definitely work for you,

new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... voids) {
                try {
                    URL url = new URL("http://YOUR_URL_HERE");
                    int fileLength = url.openConnection().getContentLength();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return null;
            }         
        }
Related