I want to retrieve the own mobile number and the IMEI.
How do I get this information from the Android phone?
use
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
String imei = tm.getDeviceId();
String phone = tm.getLine1Number();
but its not always reliable on for example non phone device.
and you should also add this following permission to your AndroidManifest.xml file
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
getLine1Number();
this method returns the phone number string for line 1,
i.e the MSISDN for a GSM phone. Return null if it is unavailable.
but what about CDMA phone?
Note : this method works only for few cell phone not for all devices
.
Related
I want to verify that user cell number is same as the sim number used in the device during registration in android application.
How do I get the sim number in my app to compare with the user entered number?
If it is impossible then any other verification process?
This code can find the sim number but only if the number is saved our phone
directory or we can never find the sim number in any case.
TelephonyManager telephonyManager = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
mobile number = telephonyManager.getLine1Number();
Really it is impossible only those device which has saved their sim number
can possible. OTP verification process is best for this , please enter your
number and get a otp to verify.
Try following code to get sim serial number and get sim number
TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String getSimSerialNumber = tManager.getSimSerialNumber();
String getSimNumber = tManager.getLine1Number();
Log.v(TAG, "getSimSerialNumber : " + getSimSerialNumber +" ,getSimNumber : "+ getSimNumber);
Add below permission into your Androidmanifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
You can find the first sim number using this code.
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
mobileNumber = telephonyManager.getLine1Number();
Add this uses-permission also in manifest.
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
This code will help you but some time it does not return the exact result. Best option is to verify the number after asking the user for their mobile number.
This would help you, it has helped me.
I need to make sure the SIM card can be used without entering pin in designated device(s), but it must be required in other devices. (Devices in use are rooted, application is installed as system app)
What I want is to identify a SIM card, and enter the pin programmatically, if one is already known/saved.
I am able to enter the known pin code, when one is required, but I have a problem with SIM identification.
I found out that I am not able to get SIM serial number or subscriber id before the correct PIN is entered.
The method I am using (with permissions and etc.):
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getSimSerialNumber();
The thing is, this method returns null, if pin is required and not yet entered.
My question is if there is some kind of workaround for this.
Is it possible at all?
Is there another approach?
Ideas and approaches appreciated.
Thanks in advance.
TelephonyManager tm = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
}
String simID = tm.getSimSerialNumber();
String telNumber = tm.getLine1Number();
String IMEI = tm.getDeviceId();
Permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Your issue:
The phone number returned is whatever is stored on the SIM card's MSISDN, which is not filled by some operators. Try Airtel, Vodafone if in India.
Which commands should I use in order to get the sim phone number from an Android mobile phone?
Exploring the sample of phone dialer i found "PhoneDialerService.GetCarrier" but with no option for getting mobile's phone number.
If the device uses only one sim card use :
TelephonyManager phoneManager = (TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = phoneManager.getLine1Number();
In case the device uses two or more sim cards, use:
TelephonyManager phoneManager = (TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String simSerialNumber = phoneManager.getSimSerialNumber();
Don't forget the permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Note that there isn't any guaranteed solution. This won't work(might return null) on every device/country because phone numbers are not physically stored on all SIM cards. The best solution is to ask the user to enter his/her phone number once and store it, and ask if number is ported/changed.
I am using following android code to get mobile number and it's working on android emulators only:
TelephonyManager tm =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String number = tm.getLine1Number();
But when I tested it in real device (Samsung Galaxy Chat B5330) it gives nothing (Empty String)
Please help with some code snippet.
For GSM, the phone number is on the SIM card, and some carriers just don't put it on the card, and then the phone does not know what it is, but in this case you
should get an empry string rather than a null
if the carrier stores the number on your SIM, go to Settings -> About Phone -> Status -> My phone Number. If it displays unknown there, then your number is not stored on the SIM.
get IMEI use:
TelephonyManager tm =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
imei_no = tm.getDeviceId();
Add permission
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
See this
You have to use Telephony Manager;If at all you not found the contact no. of user;
You can get Sim Serial Number of Sim Card and Imei No. of Android Device by using the same Telephony Manager Class...
Add permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Import:
import android.telephony.TelephonyManager;
Use the below code:
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
imei = tm.getDeviceId();
// get SimSerialNumber
simSerialNumber = tm.getSimSerialNumber();
I am working in my application and fetching phone number using the method:
TelephonyManager phoneManager = (TelephonyManager)appContext.getSystemService(Context.TELEPHONY_SERVICE);
number = phoneManager.getLine1Number();
It is working well and good with all the SIM card, but getting problem in Airtel provider SIM card.
I am getting blank while trying with this SIM card.
I don't know why Android API is dealing differently with different providers. Please suggest me.
It is because the MSISDN number is not filled on the SIM card by the operator. unfortunately nothing you can do about that.
Thread with some insight on it here
You have to use Telephony Manager;If at all you not found the contact no. of user; You can get Sim Serial Number of Sim Card and Imei No. of Android Device by using the same Telephony Manager Class...
Add permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Import:
import android.telephony.TelephonyManager;
Use the below code:
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
imei = tm.getDeviceId();
// get SimSerialNumber
simSerialNumber = tm.getSimSerialNumber();