I'm developing this Android app for my company (let's say the main domain is mycompany.com
) and I need to open the company's website with the specific TLD for the current country the device is located. So, locale based country codes are no good for me.
I mean, if you are currently abroad in Spain and you open our app, it should open mycompany.es
, if you are in Italy it should open mycompany.it
and so on. I don't need this for every possible country, just a few, the fallback will be mycompany.com
if the current country code doesn't match any of the specific ones.
I really need this before doing anything else on my app, this will be a WebView
opening the company's web app. In other words, until I get the country code the device is in, the app is unusable. This is because some countries (like Spain) forces us to have only mycompany.es
while the mycompany.com
is completely blocked at the ISP level.
I need this to work across all devices, phones/tablets, all mobile networks or just Wi-Fi. Stuff like TelephonyManager.getNetworkCountryIso()
probably don't help.
I need to get the location either with LocationManager
or Google's Location Services API. With any of them I need to get the last know location but if for some reason I don't get one, I need to request location updates and wait for it. With Google's services there's also the caveat where the user might have Location Services disabled, which is a problem. I'd have to fallback to LocationManager
which doesn't seem as reliable.
All these solutions seem to cumbersome just to get the current country code of the device just to load the WebView URL in the correct domain. But I guess I don't have any other choice.
Unless someone knows of a better solution to this problem... Thoughts?