Android Phone Number Get getMy10DigitPhoneNumber(Context ctx)

Here you can find the source of getMy10DigitPhoneNumber(Context ctx)

Description

get My Digit Phone Number

Declaration

public static String getMy10DigitPhoneNumber(Context ctx) 

Method Source Code

//package com.java2s;

import android.content.Context;

import android.telephony.TelephonyManager;

public class Main {
    public static String getMy10DigitPhoneNumber(Context ctx) {
        try {//from  w ww  . j  a v a 2 s.  c o  m
            String s = getMyPhoneNumber(ctx);
            return s.substring(2);
        } catch (Exception e) {
            return "";
        }

    }

    public static String getMyPhoneNumber(Context ctx) {

        try {
            TelephonyManager mTelephonyMgr;
            mTelephonyMgr = (TelephonyManager) ctx
                    .getSystemService(Context.TELEPHONY_SERVICE);
            return mTelephonyMgr.getLine1Number();
        } catch (Exception e) {
            return "";
        }

    }
}

Related

  1. getPhoneNumber(Context context)
  2. getPlainPhoneNumber(String phoneNumber)
  3. getMyPhoneNumber(Context ctx)
  4. getPhoneNumber(int contactId)