Reputation: 650
I am developing an app that requires to get the IMSI. I use:
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String imsi = mTelephonyMgr.getSubscriberId();
It works for most phones, but a few handsets only return 6 digits instead of 15. Which is wrong.
Anyone knows an alternative way to retrieve the IMSI programatically? Other APIS? methods?
Regards
Upvotes: 20
Views: 51152
Reputation: 40381
According to this post you can use
String imsi = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI);
but SystemProperties is not directly accessible, so you will need to use one of the tricks in the answers for this question: Where is android.os.SystemProperties
You may also need SystemProperties
source.
Upvotes: 8
Reputation: 89
This code works well in my project.
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String imsi = telephonyManager.getSubscriberId();
and don't forget the permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Upvotes: 7
Reputation: 51
first: from Wiki
An IMSI is usually presented as a 15 digit long number, but can be shorter
shorter refers to an older imsi model that was 14 digits. it isn't relevant here
second: it not depends on handset but rather on network
it returns 6 digits because the android software on that particular handset is configured to return only the non-personal identifying part of the imsi - the first 6 digits which define the country and network operator
Upvotes: 5