I wonder if it's possible to access to the SIM card with an Android Application
You can get the IMEI like this (but is it what you want ?), just an exemple :
mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imei = mTelephonyMgr.getDeviceId();
Likewise, you have
String getSimCountryIso():
Returns the ISO country code equivalent for the SIM provider's country code.
String getSimOperator(): Returns the MCC+MNC (mobile country code + mobile network code) of the provider of the SIM.
String getSimOperatorName(): Returns the Service Provider Name (SPN).
String getSimSerialNumber(): Returns the serial number of the SIM, if applicable.
int getSimState(): Returns a constant indicating the state of the device SIM card.
String getSubscriberId(): Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
For more, take a look at this page
and don't forget to add the correct permission in the manifest (getDeviceId() => Requires Permission: READ_PHONE_STATE)
Without SmartCardAPI from SEEK(Secure Element Evaluation Kit) its never possible. In majority Android phones available in market SmartCardAPI is not implemented. So either you build your own Android after integrating the SmartCardAPI code or wait for some decent phone with this feature to come out. You can find the patch file for implementation here.
SmartCard API for Android might be of interest for you:
http://code.google.com/p/seek-for-android/
SIM card access is only possible for system applications:
Low level access to the SIM card is not available to third-party apps.
The OS handles all communications with the SIM card including access
to personal information (contacts) on the SIM card memory.
Applications also cannot access AT commands, as these are managed
exclusively by the Radio Interface Layer (RIL). The RIL provides no
high level APIs for these commands.
source: https://source.android.com/security/overview/app-security.html#sim-card-access
SEEK is most useful one,but majority Android phones are not support that.So,maybe we can assess SIM card by some other method like read SMS(in SIM card).
You should use IccFileHandler in interal api of android using java reflection .
It is located at framework/base/telephony
Related
Could I get MCC & MNC of the other party, either on an incoming or an outgoing call?
I am aware that you can get your own information from the SIM card but I am interested for the information of my contacts.
I guess I must be able to retrieve such information during a phone call.
So two main questions:
Is it allowed from the protocol?
Are there any classes inside Android API that provide such information? (looked up inside TelephonyManager but did not find any)
Like payeli has answered: No, you cannot.
Firstly, because there is no API for accessing the other party's cellular information. Secondly, because Android doesn't actually know. You can delve into the source code of the TelephonyManager, and you'll see that it only contains information about the local telephony provider.
Furthermore, the internal Android class Connection also shows no hint of any such information. (Regardless of the information it contains, it isn't accessible from the API, not even via reflection.)
That being said, there are currently services that provide some insight into phone numbers. Here in the Netherlands, KPN provides an API for looking up caller information, including the current coverage state of the phone, whether it's roaming or not, and other details. I'm not sure if the API is public yet or not, but perhaps there's a similar service available in your region.
No, you can only retrieve the MCC and MNC of your phone, not for third party numbers to which you make or recieve calls.
Reason: Calls target a phone number, not the MCC/MNC of the sending/receiving devices. The MCC / MNC tuple is used to uniquely identify a mobile phone operator/carrier, so if user is using carrierX at present, he will have one value of MCC/MNC, and if user changes mobile carrier/operator but retains same phone number, the the value of MCC/MNC will change but phone-number will still be constant.
So the mapping between phone number of a contact and MCC/MNC of their carrier are not fixed. So:
Could I get MCC & MNC of the other party, either on an incoming or an outgoing call? NO
I want to get IMSI invoking TelephonyManager.getSubscriberId(), but sometimes get 334050xxxxxx, and sometimes get 222013xxxxxx, why? I use the some one USIM card.
Most likely your card has Dual IMSI application (or Multi IMSI application). One IMSI is used for home and partners network, and another one for international use (roaming).
I suggest to use ICCID for identification, because it is unique for each card. You can use Telephony#getSimSerialNumber().
I want to retreive mobile number of device programatically. My code is:-
TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String strMobileNumber = telephonyManager.getLine1Number();
and I have set READ_PHONE_STATE permission in AndroidManifest.xml file. This is working on emulator but on actual device with eclair version, it is returning empty string. Is there any other way to get mobile no?
There is no reliable way to "retreive mobile number of device programatically", AFAIK. getLine1Number() reports the number supplied by the SIM card for GSM phones, and the mobile number does not need to be on the SIM card.
I want to get the mobile number of a sim which is inserted into the device. I know as pr the android SDK TelephoneManger is the class by which we can get it by getLine1Number() method. but it always returns null values.
Queries:
Can i get mobile number from
device?
Is it a sim dependent or in some case
also device dependent?
Any other ways to get the mobile number from device?
You are using correct and the only approach available to the common user (AFAIK). It is mainly SIM dependent (it is not obligatory to have ), and in some cases may be device dependent (getLine1Number() not correctly implemented).
To be more precise, IMSI uniquely identifies SIM. But MSISDN (the subscriber number) is not uniquely related to SIM, as it is possible to change MSISDN on the SIM. Network may use IMSI from SIM to find MSISDN in the HLR and establish the call.
So, MSISDN is not mandatory to be on the SIM.
You should look at this question and its comments.
Some SIM cards seems to cause getLine1Number() to return null... and no one has found a way to deal with this.
More information here
In that case you always save your phone no using SharedPreference by using the method getLine1Number() method. when you install your application then your phone number is saven and when when new sim card is used then send SMS to ur registered number. you have to always check after starting the application that your stored number is same with your new number.if same nothing will be happned ,if not same then ur app will send SMS.
I wonder if it's possible to access to the SIM card with an Android Application
You can get the IMEI like this (but is it what you want ?), just an exemple :
mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imei = mTelephonyMgr.getDeviceId();
Likewise, you have
String getSimCountryIso():
Returns the ISO country code equivalent for the SIM provider's country code.
String getSimOperator(): Returns the MCC+MNC (mobile country code + mobile network code) of the provider of the SIM.
String getSimOperatorName(): Returns the Service Provider Name (SPN).
String getSimSerialNumber(): Returns the serial number of the SIM, if applicable.
int getSimState(): Returns a constant indicating the state of the device SIM card.
String getSubscriberId(): Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
For more, take a look at this page
and don't forget to add the correct permission in the manifest (getDeviceId() => Requires Permission: READ_PHONE_STATE)
Without SmartCardAPI from SEEK(Secure Element Evaluation Kit) its never possible. In majority Android phones available in market SmartCardAPI is not implemented. So either you build your own Android after integrating the SmartCardAPI code or wait for some decent phone with this feature to come out. You can find the patch file for implementation here.
SmartCard API for Android might be of interest for you:
http://code.google.com/p/seek-for-android/
SIM card access is only possible for system applications:
Low level access to the SIM card is not available to third-party apps.
The OS handles all communications with the SIM card including access
to personal information (contacts) on the SIM card memory.
Applications also cannot access AT commands, as these are managed
exclusively by the Radio Interface Layer (RIL). The RIL provides no
high level APIs for these commands.
source: https://source.android.com/security/overview/app-security.html#sim-card-access
SEEK is most useful one,but majority Android phones are not support that.So,maybe we can assess SIM card by some other method like read SMS(in SIM card).
You should use IccFileHandler in interal api of android using java reflection .
It is located at framework/base/telephony