简体   繁体   中英

Get the IMSI number or destination phone number from incomming message (SMS)

I am developing an application that requires the IMSI/phone number of the device(with multiple SIM cards) which receives an sms.

This is basically for identification purpose of which SIM is receiving the sms and later perform further operations.

I have thoroughly searched the SMSMessage Api, but did not find a suitable solution.

Any help would be greatly appreciated.

As I know you can not get the destination phone number, IMSI from the incoming SMS.

You can get the IMSI and phone Number of SIM like this way.

You can get the IMSI number of SIM but I don't think you will be able to get the phone number of all SIM because some manufacture did not save the phone number in SIM so you will get the NULL.

In Android, No way using Android SDK to get the second SIM information. You can get the information of first SIM only.

Android SDK support the first SIM information and Dual SIM features are available from manufacture side hence not officially supported from Android SDK.

Add this AndroidManifest.xml

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Add this in where you want to get SIM details.

TelephonyManager telemamanger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

To get the IMSI of 1st SIM

String imsi = telemamanger.getSimSerialNumber();

To get the Phone Number of 1st SIM

if(telemamanger.getLine1Number() != null)
    String phoneNumber = telemamanger.getLine1Number();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM