Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the phone number of the phone in android code?

Tags:

android

I tried googling in google but unable to find the answer

Will anyone please let me know, how can i retrieve the current phone number from the android code. I think phone number will be stored in the sim card.

Thanks & Regards, SSuman185

like image 315
Suman Avatar asked Feb 08 '11 07:02

Suman


People also ask

How do you find your phone number on Android?

On Android the most common path to finding your number is: Settings > About phone/device > Status/phone identity > Network. This slightly differs on Apple devices, where you can follow the path of Settings > Phone > My Number.

How do I know my phone number code?

Here's is the USSD code for Airtel, BSNL, Jio, and Vi to look for your mobile number: Airtel- *282# BSNL- *222# Jio- *1#

How can I get mobile number programmatically?

Navigate to the app > res > layout > activity_main. xml and add the below code to that file. Create a TextView to display the mobile number.

How can I find my mobile number from my SIM card?

You can also use your phone's settings to find out your phone number. However, the most popular and the easiest method to find out the mobile number from SIM is the dial the USSD code given by the respective network provider for this purpose. Here are the USSD codes of different networks to find out the mobile number.


1 Answers

You can try:

TelephonyManager phoneManager = (TelephonyManager) 
    getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = phoneManager.getLine1Number();

Needs READ_PHONE_STATE permission.

like image 147
Sebastian Roth Avatar answered Nov 09 '22 01:11

Sebastian Roth