开发者

Read mobile provider from the phone

开发者 https://www.devze.com 2023-01-05 21:37 出处:网络
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开发者_Go百科. Concerning mobile phone tarifs my co

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开发者_Go百科. 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:

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消