My application requires using internet connection to download some file from a link. I have a internet connection which uses proxy and needs authentication. Somehow when I try to connect to internet it never asks for this authentication hence is unable to download file.
What I want to ask is that is there any way to detect if the internet connection of the user requires authentication to download files from internet, so that in-case if it is required my application can ask the user to open a normal internet browser of device and provide the wanted authentication.
This is a very genuine case and will cause trouble when your application tries to access internet in an organizational body like in an institute or company which uses proxy for letting users to connect to internet.
As I have not received any answer on this question I am going to tell the procedure followed by me for checking this, as sometimes for your application to be unable to access internet can make it dead.
At first I check if internet connection is available on the device by simple state checking of the device using this
The above code gives information on whether internet connection is available or not but it fails to tell if the internet connection requires authentication (hence leading to nothing getting downloaded or corrupted file or zero size file to be created in the download file location), hence after checking the above condition I try to access a link to download and then use this logic.
I have provided a link to a small .zip file from internet which my application tries to download when a button to access internet is pressed (like user clicking on “update the database” of application). I have used the information given in this question ( Download and Extract Zip File in Android ), and then I extract the downloaded file in a unzipping location.
After this I have created a check option (being already aware of exact name of the file that exists inside the .zip file), which checks whether this file has been created in the unzipping location mentioned by me while unzipping.
If the file does not exist, you just give them an option to open browser and provide the authentication and then return back to your application like such: