19

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

user370305
  • 108,599
  • 23
  • 164
  • 151
omega
  • 630
  • 1
  • 6
  • 16
  • Well, It turned out that some Android handsets do not return the full Imsi (bug). I used some special hardware to extract the imsi from the sim and it extracted the full imsi, which means that the sim was fine. Thus, the problems is Android unable to extract the full IMSI. I found this bug in the Sony Ericsson Mini Experia . – omega Jun 01 '11 at 16:08

3 Answers3

7

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"/>
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
juyujuyu
  • 89
  • 1
  • 2
  • 2
    While I encourage you to become active on SO, this is an answer to a question asked 4 years ago. Also, your answer doesn't seem to bring any new outstanding elements to the existing answers and the original question has been flagged by the author as answered. Software and SO are evolving fast, please consider looking at new questions or unanswered questions to answer. – Jonathan Drolet Apr 16 '15 at 03:14
7

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.

Community
  • 1
  • 1
Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • I was unable to find any mentions of class `android.telephony.TelephonyProperties`, only `com.android.internal.telephony.TelephonyProperties`, but there is no `PROPERTY_IMSI` constant there. – Miha_x64 Feb 17 '17 at 17:03
5

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

animuson
  • 53,861
  • 28
  • 137
  • 147
bogdan
  • 51
  • 1
  • 1