Example usage for android.telephony TelephonyManager getLine1Number

List of usage examples for android.telephony TelephonyManager getLine1Number

Introduction

In this page you can find the example usage for android.telephony TelephonyManager getLine1Number.

Prototype

@SuppressAutoDoc 
@RequiresPermission(anyOf = { android.Manifest.permission.READ_PHONE_STATE,
        android.Manifest.permission.READ_SMS, android.Manifest.permission.READ_PHONE_NUMBERS })
public String getLine1Number() 

Source Link

Document

Returns the phone number string for line 1, for example, the MSISDN for a GSM phone.

Usage

From source file:Main.java

public static String getPhoneNumber(Context context) {
    TelephonyManager phoneMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String childMobile = phoneMgr.getLine1Number();
    if (childMobile == null) {
        return null;
    } else {/*from ww  w. j a  v a 2  s  . c  o  m*/
        return childMobile;
    }
}

From source file:Main.java

public static String getPhone(Context context) {
    TelephonyManager mTelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String num = mTelephonyMgr.getLine1Number();

    if (TextUtils.isEmpty(num)) {
        return "";
    } else {// w w w.ja  v  a  2 s  .  co  m
        return num;
    }
}

From source file:Main.java

public static String getLocalPhoneNo(Context context) {
    String NativePhoneNumber = null;
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    NativePhoneNumber = telephonyManager.getLine1Number();
    return NativePhoneNumber;
}

From source file:Main.java

public static String getPhoneNumber(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager.getLine1Number() == null || telephonyManager.getLine1Number().length() < 11) {
        return null;
    } else {/*from w  w w.  ja  v a  2 s. co m*/
        return telephonyManager.getLine1Number();
    }
}

From source file:Main.java

public static String getPhoneNumber(Context context) {
    TelephonyManager mTelephonyMgr;
    mTelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return mTelephonyMgr.getLine1Number();
}

From source file:Main.java

private static String getPhoneNumber(Context context) {
    String result = null;//  w  w w.j av a  2s  . com
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        result = tm.getLine1Number();
    } catch (Exception e) {
        Log.w(LOG_TAG, e);
    }
    return result == null ? "" : result;
}

From source file:Main.java

public static String getMyPhoneNumber(Context ctx) {

    try {//from  ww w .  j  ava 2s  .co m
        TelephonyManager mTelephonyMgr;
        mTelephonyMgr = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
        return mTelephonyMgr.getLine1Number();
    } catch (Exception e) {
        return "";
    }
}

From source file:Main.java

public static String getPhoneNumber(Context context) {
    if (context == null)
        return "";
    TelephonyManager tMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tMgr == null)
        return "";
    String mPhoneNumber = tMgr.getLine1Number();

    return mPhoneNumber;
}

From source file:Main.java

public static String getPhoneNumber(Context context) {
    TelephonyManager tMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String phone = "";
    try {// w w  w  .  jav  a 2 s . co  m
        if (tMgr.getLine1Number() != null) {
            phone = tMgr.getLine1Number();
        }
        if (phone.length() == 10)
            return phone;

        phone = phone.substring(phone.length() - 10, phone.length());
        phone = "0" + phone;

    } catch (Exception e) {
        e.printStackTrace();
    }
    // Log.d("Phone Number ",phone);
    // phone="01050950425";
    // phone="01100110011";
    return phone;
}

From source file:Main.java

public static String getPhoneNumber(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null) {
        return "null";
    } else {//from   w w w  . ja va  2s  .com
        String number = tm.getLine1Number();
        return number;
    }
}