Android Utililty Methods Phone Number Get

List of utility methods to do Phone Number Get

Description

The list of methods to do Phone Number Get are organized into topic(s).

Method

StringgetPhoneNumber(Context context)
get Phone Number
TelephonyManager tm = (TelephonyManager) context
        .getSystemService(Context.TELEPHONY_SERVICE);
return tm.getLine1Number();
StringgetPlainPhoneNumber(String phoneNumber)
Convert a formatted phone number into a plain digit-only phonumber
if (phoneNumber == null || phoneNumber.isEmpty())
    return "";
String newPhoneNumber = new String(phoneNumber);
newPhoneNumber = newPhoneNumber.replace(" ", "");
newPhoneNumber = newPhoneNumber.replace("(", "");
newPhoneNumber = newPhoneNumber.replace("-", "");
newPhoneNumber = newPhoneNumber.replace(")", "");
newPhoneNumber = newPhoneNumber.replace("+", "");
...
StringgetMy10DigitPhoneNumber(Context ctx)
get My Digit Phone Number
try {
    String s = getMyPhoneNumber(ctx);
    return s.substring(2);
} catch (Exception e) {
    return "";
StringgetMyPhoneNumber(Context ctx)
get My Phone Number
try {
    TelephonyManager mTelephonyMgr;
    mTelephonyMgr = (TelephonyManager) ctx
            .getSystemService(Context.TELEPHONY_SERVICE);
    return mTelephonyMgr.getLine1Number();
} catch (Exception e) {
    return "";
StringgetPhoneNumber(int contactId)
This method used to get phone number from contact id.
String phoneNumber = "";
final String[] projection = new String[] { Phone.NUMBER,
        Phone.TYPE, };
final Cursor phone = mSmartAndroidActivity.managedQuery(
        Phone.CONTENT_URI, projection, Data.CONTACT_ID + "=?",
        new String[] { String.valueOf(contactId) }, null);
if (phone.moveToFirst()) {
    final int contactNumberColumnIndex = phone
...