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 getPhoneStatus(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String str = "";
    str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n";
    str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
    str += "Line1Number = " + tm.getLine1Number() + "\n";
    str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
    str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
    str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
    str += "NetworkType = " + tm.getNetworkType() + "\n";
    str += "honeType = " + tm.getPhoneType() + "\n";
    str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
    str += "SimOperator = " + tm.getSimOperator() + "\n";
    str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
    str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
    str += "SimState = " + tm.getSimState() + "\n";
    str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
    str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
    return str;/*from w w w.  jav  a  2s  . c  om*/
}

From source file:Main.java

public static String getDeviceInfo(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    StringBuilder sb = new StringBuilder();
    sb.append("\nDeviceId(IMEI) = " + tm.getDeviceId());
    sb.append("\nDeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion());
    sb.append("\nLine1Number = " + tm.getLine1Number());
    sb.append("\nNetworkCountryIso = " + tm.getNetworkCountryIso());
    sb.append("\nNetworkOperator = " + tm.getNetworkOperator());
    sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName());
    sb.append("\nNetworkType = " + tm.getNetworkType());
    sb.append("\nPhoneType = " + tm.getPhoneType());
    sb.append("\nSimCountryIso = " + tm.getSimCountryIso());
    sb.append("\nSimOperator = " + tm.getSimOperator());
    sb.append("\nSimOperatorName = " + tm.getSimOperatorName());
    sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber());
    sb.append("\nSimState = " + tm.getSimState());
    sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId());
    sb.append("\nVoiceMailNumber = " + tm.getVoiceMailNumber());

    return sb.toString();
}

From source file:org.cryptocall.ui.WizardActivity.java

public static void prefillTelephoneNumber(Context context, EditText editText) {
    // prefill telephone number if available
    TelephonyManager tMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String telephoneNumber = tMgr.getLine1Number();
    if (telephoneNumber != null) {
        Log.d(Constants.TAG, "TelephoneNumber: " + telephoneNumber);
        editText.setText(telephoneNumber);
    } else {// w w w .jav  a2 s .  c o  m
        Log.d(Constants.TAG, "TelephoneNumber could not be retrived with TelephonyManager!");
    }
}

From source file:com.vinexs.tool.Utility.java

/**
 * <p>Get user phone number.</p>
 * Required Permission &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"/&gt;
 *
 * @param context Application context./*  w w w .  j  a  v  a  2s  .  c om*/
 * @return Phone number in string.
 */
public static String getUserTelNo(Context context) {
    try {
        TelephonyManager tMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return tMgr.getLine1Number();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static String queryDevicePhone(Context context) {
    TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (manager != null) {
        operatorCode = manager.getNetworkOperator();
        if (operatorCode == null || operatorCode.length() == 0)
            operatorCode = manager.getSimOperator();
        isoCountryCode = manager.getNetworkCountryIso();
        if (isoCountryCode == null || isoCountryCode.length() == 0)
            isoCountryCode = manager.getSimCountryIso();
        if (isoCountryCode == null || isoCountryCode.length() == 0)
            isoCountryCode = context.getResources().getConfiguration().locale.getCountry();
    }// w  w w  .ja va  2 s.c o m
    return manager.getLine1Number();
}

From source file:ph.sakay.gateway.RoutingService.java

private String getOwnNumber() {
    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String number = tm.getLine1Number();
    if (number == null)
        number = "unknown";
    return number;
}

From source file:com.smithleedon.device.MyPhoneNumber.java

private void initTelephonyReceiver() {
    mGap = this.cordova;
    TelephonyManager mTelephonyMgr = (TelephonyManager) mGap.getActivity()
            .getSystemService(Context.TELEPHONY_SERVICE);
    strPhoneNumber = mTelephonyMgr.getLine1Number();
    strPhoneNumber = strPhoneNumber.replace("-", "").replace("+82", "0");
}

From source file:com.phonegap.Device.java

public String getLine1Number() {
    TelephonyManager operator = (TelephonyManager) this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
    return operator.getLine1Number();
}

From source file:com.fizz.StickyFragment.java

private void getNameNumber() {
    TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    number = tm.getLine1Number();

    Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
    Account[] accounts = AccountManager.get(getActivity()).getAccounts();
    for (Account account : accounts) {
        if (emailPattern.matcher(account.name).matches()) {
            name = account.name;//w  w w.ja  v a  2 s . c  o m
        }
    }
}

From source file:com.google.zxing.client.android.result.ClickVURIResultHandler.java

public String getTelNumber() {
    TelephonyManager telephonyManager = (TelephonyManager) getActivity()
            .getSystemService(getActivity().TELEPHONY_SERVICE);
    return telephonyManager.getLine1Number();
}