I want to get my network operator name in my app.
I am using fallowing methods in the TelephonyManager to get this:
TelephonyManager mTeleManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
mTeleManager.getSimOperatorName();
mTeleManager.getNetworkOperatorName();
mTeleManager.getSimOperator()
But I am getting empty values from the "getSimOperatorName()" and "getNetworkOperatorName()"..
I am getting numeric code from this "getSimOperator()" method, But I want know the alphabetic form of the operator name . Some thing like "T-Mobile" for Tmobile networks.
Pl. suggest me how to do this.
thanks.
Have you tried it on different phones/with different sim cards?
According to TelephonyManager.getLine1Number() returns Null
Hi All,
Here comes an explanation for this. It is not actually an issue, both information depends on some fields on the SIM card that are optional. So it might be empty if the SIM has no such optional fields or if the operator has set it empty.
Regards,
He is talking about
TelephonyManager.getLine1Number()
TelephonyManager.getSimOperatorName()
Related
I'm updating some code to use the Multi SIM support that was added to Android in 5.1. We examine the SIM operator (or the MCC+MNC combo) a lot in our app, so the code I'm writing involves migrating from reliance on TelephonyManager.getSimOperator() to getting SubscriptionInfos from the SubscriptionManager, each of which gives access to the MCC and MNC for a SIM.
//old way – can only access one SIM
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String simOperator = telephonyManager.getSimOperator();
//new way - gives access to all SIMs
SubscriptionManager subscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
List<SubscriptionInfo> subInfoList = subscriptionManager.getActiveSubscriptionInfoList();
for(SubscriptionInfo info : subInfoList) {
int mcc = info.getMcc();
int mnc = info.getMnc();
//do some stuff...
}
I'm finding that because it's returning ints for MCC and MNC, you lose leading zeros that are in some of the MNCs. To see some examples, check out the table here. When you concat MCC+MNC you get the SIM operator, so it is important to keep the zeros that are often present. For example, NEXTEL in Mexico has a SIM operator value of "334090," but because the SubscriptionInfo returns ints for MCC and MNC, you get the values 334 and 90, respectively.
Given this issue, how can you reliably link a SubscriptionInfo's MCC+MNC pair to a particular SIM operator in a list of known SIM operators? Is this an oversight in the design of this API? Is there any other way to get the SIM operator for every SIM card that's in the multi-SIM phone?
MCC are always 3 digits, the rest is MNC, which as you correctly said, may have 2 or 3 digits.
If you parse the int to String, you can just get sub string of it and process the info as required.
Also it's a hidden method, but you can access it by reflection, to get the info you want in String format, this exists at least from Android 6 and Android 7
public String getSimOperator(int subId)
But I think SubscriptionManager way is safer since it's open API and for the moment you don't need to bother with Android versions handling it differently.
The best way to achieve this is to read IMSI from the SIM card. If you are reading the MNC+MNC directly and your user is on roaming or connected to another network then the values returned won't be reliable.
E.g. If your user is NEXTEL customer but is travelling or due to network connection issues connects to another network, lets say Telcel, then the value returned from MCC+MNC will be from Telcel.
In order to reliably match the operator of current SIM to predefined list, read IMSI value from SIM card using getSubscriptionId() from Telephony manager.
IMSI starts with MCC+MNC of the operator. You can easily check if MCC+MNC matches as follows
final String mccMncToCompare = "334090"; //You can also use Integer instead of string. You just have to perform type conversion
final TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
final String imsi= tm.getSubscriberId();
final boolean mccMncMatched = imsi.startsWith(mccMncToCompare);
Do we have any flag or value on the phone which can help decide this ?
I think it's not possible, you can just differenciate whether you're using roaming or not, but at least officially I can't find any info about this.
getRoaming() from ServiceState class.
isRoaming() from NetworkInfo class.
Roaming detection in StackOverflow.
---- EDIT ----
As probably there's not a built-int method for this, you could simply define and keep an internal list of national telephony companies and see whether the SIM's operator match one of them, in which case you'll be having a national roaming, an international roaming if the current operator is not the same as the SIM's and it's not in your list, or no-roaming if the current operator matches the SIM's operator. The negative thing is that you'd need to keep track of all national operators and add it to the list if there's some new, but that's something that doesn't happen too often (or at least here).
So basically it would be something like this:
TelephonyManager telephMan = ((TelephonyManager) Context.getSystemService(Context.TELEPHONY_SERVICE));
// This will be the current registered operator
String currentOperatorName = telephMan.getNetworkOperatorName();
// This will return the SIM operator
String simOperatorName = telephonyManager.getSimOperatorName();
// Additionally you'll have to keep a list of national operators
ArrayList<String> myCountryOperators = new ArrayList<String();
myCountryOperators.add("...");
myCountryOperators.add("...");
...
if (currentOperatorName.equals(simOperatorName)) {
// No roaming
}
else if (myCountryOperators.contains(currentOperatorName)) {
// National roaming
}
else {
// International roaming
}
if it's a GSM phone, in my opinion is easier to compare the country code set in the SIM card with the country code of network carrier with TelephonyManager.getNetworkCountryIso() and TelephonyManager.getSimCountryIso()
If they match you're in same country, otherwise don't. And you don't need to keep a list of names...
In an Android app I've got a couple contacts from my contacts list. They can be either emails, phone numbers, or even other things. I now want to check which type it is and bind specific actions to them.
For example, if it is a type vnd.android.cursor.item/email_v2, I want to send a POST message with just the email field, and if it is a type vnd.android.cursor.item/phone_v2 I want to send a POST message with just the phone field.
Any ideas how I could check this?
I guess the way to go would be using overloading:
You implement multiple methods with different input parameters but the same name, such as:
checkContact(email_v2 email){ do things with email }
checkContact(phone_v2 phone){ do things with phone }
checkContact(String s){do things with random string }
I think you get my point.
If you want a simple if-statement, though:
if (contact instanceof vnd.android.cursor.item/email_v2){ do send }
You could try checking the class constant CONTENT_ITEM_TYPE for your different types, something like:
contact.CONTENT_ITEM_TYPE.equals("vnd.android.cursor.item/email_v2");
I am just trying to get my carrier name.
The issue while trying to use:
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE));
String carrierName = manager.getNetworkOperatorName();
That is working great unless you are a MVNO (definition here: http://en.wikipedia.org/wiki/Mobile_virtual_network_operator)
For instance, in Belgium, we have the "Base" carrier that rent the network to some MVNO, like Toledo, Allo RTL, Mobile Vikings, etc...
In my notification bar, when using such virtual operators, I get their real names, but the code above just give me "Base" as String, and not the one I want.
I hope you understand what I mean.
I don't have a MVNO SIM card but the getSimOperatorName() method of the TelephonyManager might be the method you are looking for.
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String carrierName = manager.geSimOperatorName();
I have a MVNE SIM card in Germany and the method returns an empty String, but the getNetworkOperatorName() method returns the right Operator for my SIM card.
Is it possible to find Base Station Identifying Code in android. To clarify, Let 'A' calls to 'B'. Before 'B' receive the phone call, his installed app will find
'A's BSIC and match it with a given database of BSIC( this BSIC database may be located on phone locally or
in a web or from phone network provider's database ) then will find 'A' location( Say +88017... is calling from "Dinajpur of Bangladesh" ).Is it possible ? if so how ? please help me...
Rereading the question, you want the other person's tower, not your own. No, i don't think that info is available to you. At most, you can guess by the country and region codes.
Not relevant anymore:
I believe you can achieve what you want getting the cell id in use or all the neighboring cells
TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation loc = (GsmCellLocation) mTelephonyManager.getCellLocation();
Log.d ("CID", Integet.toString(loc.getCid()));
Log.d ("LAC", Integet.toString(loc.getLac()));
// or
List<NeighboringCellInfo> list = mTelephonyManager.getNeighboringCellInfo ();
for (NeighboringCellInfo cell : list) {
Log.d ("CID", Integet.toString(cell.getCid()));
Log.d ("LAC", Integet.toString(cell.getLac()));
}
You can refer then to cell location through several open databases (e.g., http://www.location-api.com/ or http://opencellid.org/ )
If this is not enought, I suggest you to check this thread: http://groups.google.com/group/android-platform/browse_thread/thread/b55c8d3275ed7042/78d9c30c49e94a3a , specially this link: http://www.google.com/url?sa=D&q=http://www.3gpp.org/ftp/Specs/archive/27_series/27.007/27007-860.zip