Example usage for android.content Context TELEPHONY_SERVICE

List of usage examples for android.content Context TELEPHONY_SERVICE

Introduction

In this page you can find the example usage for android.content Context TELEPHONY_SERVICE.

Prototype

String TELEPHONY_SERVICE

To view the source code for android.content Context TELEPHONY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.telephony.TelephonyManager for handling management the telephony features of the device.

Usage

From source file:Main.java

public static String getDeviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId = tm.getDeviceId();
    if (deviceId == null) {
        return "-";
    } else {//from   w  w  w . j  a v a2  s  .  c o m
        return deviceId;
    }
}

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.  j a  v a  2 s .  co  m*/
        return num;
    }
}

From source file:Main.java

public static String getImsi(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return telephonyManager.getSubscriberId();
}

From source file:Main.java

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

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 w w. ja v a 2 s  .c o  m*/
    return result;
}

From source file:Main.java

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

From source file:Main.java

public static int getLat(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();

    return cellLocation == null ? -1 : cellLocation.getLac();
}

From source file:Main.java

public static String getDeviceId(Context context) {
    String deviceId = "";
    try {/* w  ww .  j a  v a2s.com*/
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        deviceId = tm.getDeviceId();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return deviceId;
}

From source file:Main.java

public static boolean isEmulator(Context context) {
    try {// w  ww . j a  v a 2  s. com
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String imei = tm.getDeviceId();
        if (imei != null && imei.equals("000000000000000"))
            return true;

        return (Build.MODEL.equals("sdk")) || (Build.MODEL.equals("google_sdk"));
    } catch (Exception ioe) {
        return false;
    }
}

From source file:Main.java

public static boolean isEmulator(Context context) {
    try {/*from  www.java  2 s.  c o m*/
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String imei = tm.getDeviceId();
        if (imei != null && imei.equals("000000000000000")) {
            return true;
        }
        return (Build.MODEL.equals("sdk")) || (Build.MODEL.equals("google_sdk"));
    } catch (Exception ioe) {
    }
    return false;
}