get Native Phone Number - Android android.telephony

Android examples for android.telephony:TelephonyManager

Description

get Native Phone Number

Demo Code

import android.content.Context;
import android.telephony.TelephonyManager;

public class Main {

  public static String getNativePhoneNumber(Context context) {

    if (null == context) {
      return null;
    }/*from w  w w  .  ja v  a 2 s.  c  o  m*/
    TelephonyManager telephonyManager;
    telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String NativePhoneNumber = null;
    NativePhoneNumber = telephonyManager.getLine1Number();
    return NativePhoneNumber;
  }

}

Related Tutorials