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 tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String result = tm.getLine1Number();
    if (result == null) {
        result = "";
    }// w  ww.j  a  v  a 2  s .  c o m
    return result;
}

From source file:Main.java

public static final String getPhoneNumber(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String number = tm.getLine1Number();
    if (number == null) {
        return "";
    }//from  www. jav  a  2 s.c  o  m
    return number;
}

From source file:Main.java

public static String getPhoneNumber(Context ctx) {
    TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    String phoneNumber = tm.getLine1Number();
    if (phoneNumber == null || phoneNumber.length() == 0) {
        return null;
    }/*from   w w  w.  j  a v  a2s. com*/
    phoneNumber = phoneNumber.replace("+82", "0");
    return phoneNumber;
}

From source file:Main.java

public static String getPhoneNumber(Context context) {
    TelephonyManager phoneMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String tel = phoneMgr.getLine1Number();
    if (tel != null) {
        tel = tel.replace("+86", "").trim();
    }/* w  w  w .  jav  a  2 s  . co m*/
    return tel;
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static boolean isMyphone(Context context, EditText myPhone) {
    TelephonyManager phoneMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String number = phoneMgr.getLine1Number();
    if (myPhone.equals(number)) {
        return true;
    } else {/*from  ww  w  .java2  s  .  c  o  m*/
        return false;
    }
}

From source file:Main.java

public static String getLocalNumber(Context context) {
    try {//from  w  w w. jav a2  s . com
        TelephonyManager tManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String number = tManager.getLine1Number();
        return number;
    } catch (Exception e) {
        return "x";
    }
}

From source file:Main.java

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

From source file:Main.java

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