Read mobile provider from the phone

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?


You could use TelephonyManager:

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

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


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.

Need Your Help