Read IMSI information via ADB on Android 12
If your apk's targetsdk <30, you can get IMSI by the following method without any permission in android 11.
Uri uri = Uri.parse("content://telephony/siminfo");
Cursor cursor = null;
ContentResolver contentResolver = getApplicationContext().getContentResolver();
cursor = contentResolver.query(uri,
new String[]{"_id", "sim_id", "imsi","icc_id","number","display_name"}, "0=0",
new String[]{}, null);
if (null != cursor) {
while (cursor.moveToNext()) {
String icc_id = cursor.getString(cursor.getColumnIndex("icc_id"));
String imsi_id = cursor.getString(cursor.getColumnIndex("imsi"));
String phone_num = cursor.getString(cursor.getColumnIndex("number"));
String display_name = cursor.getString(cursor.getColumnIndex("display_name"));
int sim_id = cursor.getInt(cursor.getColumnIndex("sim_id"));
int _id = cursor.getInt(cursor.getColumnIndex("_id"));
Log.d("Q_M", "icc_id-->" + icc_id);
Log.d("Q_M", "imsi_id-->" + imsi_id);
Log.d("Q_M", "phone_num-->" + phone_num);
Log.d("Q_M", "sim_id-->" + sim_id);
Log.d("Q_M", "display_name-->" + display_name);
}
}
Is there an android shell or adb command that I could use to get a device's IMEI/MEID?
I figured out how to do this. You need to run adb shell dumpsys iphonesubinfo
in a shell. It will give you a bit more than you need, but it will also return IMEI or MEID number.
Edit (2017): In Android 5.0+ you'll need to use the service call
command. More info about that can be found here.
How to get the phone number of an android phone via adb?
iphonesubinfo
service "keeps track" of the subscriber information including phone numbers. Unfortunately iphonesubinfo
service does not implement the dump()
method so dumpsys shows nothing. You will have to use service call
command to call IPhoneSubInfo.getLine1Number()
or IPhoneSubInfo.getMsisdn()
instead
Depending on the android version and your carrier one or two of the following commands will tell you the phone number (service call
commands require root
privileges):
service call iphonesubinfo 4
service call iphonesubinfo 5
service call iphonesubinfo 6
service call iphonesubinfo 7
service call iphonesubinfo 8
If you want to find out the proper code for your specific device - download the script from Calling Android services from ADB shell post and run it like this:
./get_android_service_call_numbers.sh iphonesubinfo | grep getLine1Number
UPDATE
Transaction codes for Android 5.0:
service call iphonesubinfo 11 # getLine1Number()
service call iphonesubinfo 15 # getMsisdn()
Transaction codes for Android 5.1:
service call iphonesubinfo 13 # getLine1Number()
service call iphonesubinfo 17 # getMsisdn()
Related Topics
How to Display a Pdf Via Android Web Browser Without "Downloading" First
How to Set Align (Right or Left) of Text in Textview, Programmatically
Aligning Textviews on the Left and Right Edges in Android Layout
Java.Io.Ioexception: Permission Denied Cannot Create File
React Native: Java_Home Is Not Set and No 'Java' Command Could Be Found in Your Path
Open Facebook Page in Facebook App (If Installed) on Android
Access Ro.Serialno from Native in Android 8
Why Does My Button Not Showing in the Layout
How to Retrieve Current Fragment in Navhostfragment
Android Force Gpu Rendering How to Enable and Disable
Method to Refresh Fragment Content When Data Changed ( Like Recall Oncreateview)
Navigate from One Fragment to Another on Click of a Button
Imageview of Png Doesn't Appear (Maybe It's Too Big)
How to Set Spinner Default by Its Value Instead of Position
Android: Mkdirs()/Mkdir() on External Storage Returns False
How to Control Navigationview Margin Between Menu Items