Take the 2-minute tour ×

I'm trying to get the phone number using below code,

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
phoneImei = tm.getDeviceId();
phoneNo = tm.getLine1Number();

but, it returns me null value. When I checked the setting, phone number was unknown. I'm using galaxy nexus. Any idea how i can solve this.?

share|improve this question
add comment

5 Answers

up vote 8 down vote accepted

Try this :

  import android.app.Activity;  
  import android.content.Context;  
  import android.os.Bundle;  
  import android.telephony.TelephonyManager;  
  import android.util.Log;  
  import android.widget.Toast;  

  public class GetMyPhoneNoActivity extends Activity {  
   public void onCreate(Bundle savedInstanceState) {  

    String number =getMyPhoneNO();  
    +number, Toast.LENGTH_SHORT).show();  
    Log.v("Debug", number);          

private String getMyPhoneNO(){  
    TelephonyManager mTelephonyMgr;    
   mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);     

    String yourNumber = mTelephonyMgr.getLine1Number();  
 //return yourNumber;   


In Your Manifest :

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

This will work pretty well.

share|improve this answer
Cannot see anydifferent from my code.. You still using getLine1Number()... –  chinna_82 Sep 20 '12 at 11:18
But It works fine on my emulator .. –  Manish Dubey Sep 20 '12 at 11:28
try to use mobile instead of emulator... put SIM on the mobile and try.. –  chinna_82 Sep 20 '12 at 11:30
go to Settings=>About phone=>Status=>(Phone identity)->Phone number, phone number is "Unknown" ? –  Manish Dubey Sep 20 '12 at 11:48
I'm gonna get groans for this, but doesn't just about everyone at StackOverflow have a problem getting phone numbers? Sorry, had to be done. But I dont think its a problem with your sim, your service provider may not have specified the number on your phone during activation. –  Manish Dubey Sep 20 '12 at 11:50
show 1 more comment

Instead of the phone number use the SIM card serial number, which always exists and is always a valid value.


SIM serial number is unique within the operator at least. So combined with


you'll have a unique identifier for a subscriber within a country.This combined with


you'll have a globally unique identifier for a subscriber.

Hope this will help.


share|improve this answer
what is the reason for adding 3 different answers ? –  Lucifer Sep 20 '12 at 14:44
Your answer is very useful but not quite what he asks about. ;) –  wojci Sep 30 '12 at 19:40
add comment

Here is my code :

 import java.lang.reflect.Method;

 import android.app.NotificationManager;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.database.Cursor;
 import android.media.AudioManager;
 import android.os.Bundle;
 import android.telephony.TelephonyManager;

 import com.android.internal.telephony.ITelephony;

  public class BlockBlackListIncomingNumber extends BroadcastReceiver {
 private Context cont;
 private Transactions transactions;
 private ITelephony itelephony;;

 int i = 1;

    /* When any incoming calls come to our cellphone number */
public void onReceive(Context context, Intent intent)
    transactions = new Transactions(context); 
                // Create an object of transaction class.
    this.cont = context; 
                 // Refer to current object of Context.
    Bundle extras = intent.getExtras(); 
                 // Getting Bundles in extras.
    String iNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); 
                 // Getting Incoming Number by which call comes that’s why we used TelephoyManager.EXTRA_INCOMING_NUMBER. 

iNumber will be incoming number.

share|improve this answer
add comment

You need to add following permission in your AndroidManifest.xml file

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
share|improve this answer
yeah...i already give the permission. but it still same... –  chinna_82 Sep 20 '12 at 10:46
do you have SIM in your device ? –  Lucifer Sep 20 '12 at 10:47
yes..i tried 2 SIMs..both giving me null value... –  chinna_82 Sep 20 '12 at 10:55
do you have GSM SIM because getLine1Number() Returns the phone number string for line 1, for example, the MSISDN for a GSM phone. –  Lucifer Sep 20 '12 at 10:58
add comment

Try implementing ITelephony interface using AIDL

share|improve this answer
And this will work on all versions of Android? Is this part of the SDK? –  wojci Sep 30 '12 at 19:38
I guess so, I have implemented it way back ago on Android 2.2. Kindly test on latest versions and let us know your findings. –  yogeshhkumarr Oct 3 '12 at 11:43
I don't think that you are right. Please see stackoverflow.com/a/9034931/1525300. –  wojci Oct 4 '12 at 6:45
add comment

Your Answer


