Android How to - Get Phone Number








Question

We would like to know how to get Phone Number.

Answer

/*w  ww  .  j  av a2 s .c o m*/
import android.content.Context;
import android.telephony.TelephonyManager;

public class Main {
  public static String getPhoneNumber(Context context){
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String phoneNumber = telephonyManager.getLine1Number();
    return phoneNumber;  
  }
  
}