0

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?

rfgamaral
  • 16,546
  • 57
  • 163
  • 275

1 Answers1

2

My initial thought is just because I am in Spain doesn't mean I suddenly know how to speak spanish. I would still want to see the website that correlates to my phones locale. But given your statement that the .com is blocked at the ISP level it looks like you have no choice. Hopefully when you open the website you can tell it the device's locale, so if I am en_us I will get the .es website in english by default.

Given the requirements you have laid out I think you just need to get a location, wait for it, and then do a location mapping to your websites locales that are supported. If doing so I'd very much recommend Location Services API over location manager. Its much more reliable and faster since it caches locations for any app that has fetched it already and automatically handles fallbacks for you.

w.donahue
  • 10,790
  • 13
  • 56
  • 78
  • What do you mean that the location services handle fallbacks for me? – rfgamaral Aug 04 '16 at 19:34
  • 1
    This topic sums it up pretty well http://stackoverflow.com/questions/33022662/android-locationmanager-vs-google-play-services – w.donahue Aug 04 '16 at 19:40
  • I came across that post before posting this question, I didn't notice anything about a fallback. But I'll take a closer look when I get home. Thanks. – rfgamaral Aug 04 '16 at 19:42
  • 1
    In short, with just the Android Location API you need to manually pick to get GPS, Network, or Passive location. Where as with the new Play Services API version it will handle all that for you automatically. All you need to do is tell it the minimum location reliability you need. Also the real main reason to use it is it can return a cached location that was requested from any other app on the phone recently. – w.donahue Aug 04 '16 at 19:42