get Phone Number from TelephonyManager - Android android.telephony

Android examples for android.telephony:TelephonyManager

Description

get Phone Number from TelephonyManager

Demo Code

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;
  }//from  w  w  w. j  a va  2 s  . c o  m

}

Related Tutorials