views:

50

answers:

2

Using my new Android phone established a small problem: I'm living in country A but my mobile provider is from country B, because it's just cheaper. Concerning mobile phone tarifs my country isn't a foreign country for country B. However I have to enable data roaming in my Android phone. The problem is, I'm also quite often in country C and every time I have to switch off data roaming.

So I thought about writing a small app which disables data roaming if I'm not in country A or B and enables it otherwise.

My first try was to define the location using GPS, but this is rather useless, because I would have to calculate for every coordinate if it is in the allowed range. So I think the better solution would by to read from the phone the current provider and if this provider isn't in the whitelist (which is defined by me), data roaming is switched off.

Do you know any other approaches? And how could I get the name of the current provider? And how to programatically disable data roaming?

+1  A: 

Can you use reverse Geocoding? Something like Nominatim? Simply send the GPS coordinates and check the country you are in.

On the other hand, this example shows you how you can get the name of the operator your phone is currently connected to.

About diabling the data roaming, it seems that entering invalid APN details does the trick.

npinti
Android has inbuilt Geocoding helpers see this http://developer.android.com/intl/de/reference/android/location/Geocoder.html
Pentium10
I thought about that, and it would be really nice, but the problem is, then I always have to have enabled GPS receiver. For various reasons, I don't want that.
Roflcoptr
You don't need to have GPS enabled, you can get coordinates from your network or WIFI.
janfsd
+5  A: 

You could use TelephonyManager:

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

Some of its methods that might be useful for your case:

tm.getNetworkCountryIso();
tm.getNetworkOperator();
tm.getNetworkOperatorName();
tm.getSimCountryIso();
tm.getSimOperator();
tm.getSimOperatorName();
janfsd