android.telephony.TelephonyManager

Here are the examples of the java api android.telephony.TelephonyManager taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

717 Examples 7

19 Source : UtilsSIMCardInfo.java
with GNU General Public License v3.0
from zhangneng

public clreplaced UtilsSIMCardInfo {

    /**
     * TelephonyManager提供设备上获取通讯服务信息的入口。 应用程序可以使用这个类方法确定的电信服务商和国家 以及某些类型的用户访问信息。
     * 应用程序也可以注册一个监听器到电话收状态的变化。不需要直接实例化这个类
     * 使用Context.getSystemService(Context.TELEPHONY_SERVICE)来获取这个类的实例。
     */
    private TelephonyManager telephonyManager;

    /**
     * 国际移动用户识别码
     */
    private String IMSI;

    public UtilsSIMCardInfo(Context context) {
        telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    }

    /**
     * Role:获取当前设置的电话号码
     * Date:2012-3-12
     * @author CODYY)
     */
    public String getNativePhoneNumber() {
        String NativePhoneNumber = null;
        NativePhoneNumber = telephonyManager.getLine1Number();
        return NativePhoneNumber;
    }

    /**
     * Role:Telecom service providers获取手机服务商信息 <BR>
     * 需要加入权限<uses-permission
     * android:name="android.permission.READ_PHONE_STATE"/> <BR>
     * Date:2012-3-12 <BR>
     * @author CODYY)
     */
    public String getProvidersName() {
        String ProvidersName = null;
        // 返回唯一的用户ID;就是这张卡的编号神马的
        IMSI = telephonyManager.getSubscriberId();
        // IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。
        System.out.println(IMSI);
        if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
            ProvidersName = "中国移动";
        } else if (IMSI.startsWith("46001")) {
            ProvidersName = "中国联通";
        } else if (IMSI.startsWith("46003")) {
            ProvidersName = "中国电信";
        }
        return ProvidersName;
    }
}

19 Source : XNetworkUtils.java
with Apache License 2.0
from youth5201314

/**
 * 获取网络运营商名称
 * <p>中国移动、如中国联通、中国电信</p>
 *
 * @return 运营商名称
 */
public static String getNetworkOperatorName() {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null ? tm.getNetworkOperatorName() : null;
}

19 Source : XNetworkUtils.java
with Apache License 2.0
from youth5201314

/**
 * 判断移动数据是否打开
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean getDataEnabled() {
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        Method getMobileDataEnabledMethod = tm.getClreplaced().getDeclaredMethod("getDataEnabled");
        if (null != getMobileDataEnabledMethod) {
            return (boolean) getMobileDataEnabledMethod.invoke(tm);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

19 Source : NetworkUtils.java
with Apache License 2.0
from yinlingchaoliu

/**
 * 判断移动数据是否打开
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean getDataEnabled() {
    try {
        TelephonyManager tm = (TelephonyManager) Utils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
        Method getMobileDataEnabledMethod = tm.getClreplaced().getDeclaredMethod("getDataEnabled");
        if (null != getMobileDataEnabledMethod) {
            return (boolean) getMobileDataEnabledMethod.invoke(tm);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

19 Source : NetworkUtils.java
with Apache License 2.0
from yinlingchaoliu

/**
 * 获取网络运营商名称
 * <p>中国移动、如中国联通、中国电信</p>
 *
 * @return 运营商名称
 */
public static String getNetworkOperatorName() {
    TelephonyManager tm = (TelephonyManager) Utils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null ? tm.getNetworkOperatorName() : null;
}

19 Source : YUtils.java
with Apache License 2.0
from yechaoa

/**
 * 是否有sim卡 即设备是否可以拨打电话等
 */
public static Boolean hreplacedim() {
    TelephonyManager telephonyManager = (TelephonyManager) getApp().getSystemService(Context.TELEPHONY_SERVICE);
    boolean result = true;
    switch(telephonyManager.getSimState()) {
        case TelephonyManager.SIM_STATE_ABSENT:
        case TelephonyManager.SIM_STATE_UNKNOWN:
            result = false;
            break;
    }
    return result;
}

19 Source : PhoneInfoUtils.java
with Apache License 2.0
from y1xian

/**
 * ================================================
 * 作    者:yyx
 * 版    本:1.0
 * 日    期:2020/10/20
 * 历    史:
 * 描    述:获取手机号
 * 并不是所有的SIM卡都能获取到手机号码,只是有一部分可以拿到。这个是由于运营商没有把手机号码的数据写入到SIM卡中,
 * 能够读取SIM卡号的有个前提,那就是SIM卡已经写入了本机号码,不然是无法读取的
 * ================================================
 */
public clreplaced PhoneInfoUtils {

    private static String TAG = "PhoneInfoUtils";

    private static TelephonyManager telephonyManager;

    // 移动运营商编号
    private static String NetworkOperator;

    public PhoneInfoUtils() {
        telephonyManager = (TelephonyManager) AppUtils.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    }

    // 获取sim卡iccid
    @SuppressLint("MissingPermission")
    public static String getIccid() {
        String iccid = "N/A";
        iccid = telephonyManager.getSimSerialNumber();
        return iccid;
    }

    // 获取电话号码
    @SuppressLint({ "MissingPermission", "HardwareIds" })
    public static String getNativePhoneNumber() {
        TelephonyManager tm = (TelephonyManager) AppUtils.getApp().getSystemService(Context.TELEPHONY_SERVICE);
        String nativePhoneNumber = "N/A";
        nativePhoneNumber = tm.getLine1Number();
        return nativePhoneNumber;
    }

    // 获取手机服务商信息
    public static String getProvidersName() {
        String providersName = "N/A";
        NetworkOperator = telephonyManager.getNetworkOperator();
        // IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。
        // Flog.d(TAG,"NetworkOperator="   NetworkOperator);
        if (NetworkOperator.equals("46000") || NetworkOperator.equals("46002")) {
            // 中国移动
            providersName = "中国移动";
        } else if (NetworkOperator.equals("46001")) {
            // 中国联通
            providersName = "中国联通";
        } else if (NetworkOperator.equals("46003")) {
            // 中国电信
            providersName = "中国电信";
        }
        return providersName;
    }

    @SuppressLint({ "MissingPermission", "HardwareIds" })
    public static String getPhoneInfo() {
        TelephonyManager tm = (TelephonyManager) AppUtils.getApp().getSystemService(Context.TELEPHONY_SERVICE);
        StringBuffer sb = new StringBuffer();
        sb.append(" \nLine1Number = " + tm.getLine1Number());
        // 移动运营商编号
        sb.append(" \nNetworkOperator = " + tm.getNetworkOperator());
        // 移动运营商名称
        sb.append(" \nNetworkOperatorName = " + tm.getNetworkOperatorName());
        sb.append(" \nSimCountryIso = " + tm.getSimCountryIso());
        sb.append(" \nSimOperator = " + tm.getSimOperator());
        sb.append(" \nSimOperatorName = " + tm.getSimOperatorName());
        sb.append(" \nSimSerialNumber = " + tm.getSimSerialNumber());
        sb.append(" \nSubscriberId(IMSI) = " + tm.getSubscriberId());
        return sb.toString();
    }
}

19 Source : PhoneInfoUtils.java
with Apache License 2.0
from y1xian

// 获取电话号码
@SuppressLint({ "MissingPermission", "HardwareIds" })
public static String getNativePhoneNumber() {
    TelephonyManager tm = (TelephonyManager) AppUtils.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    String nativePhoneNumber = "N/A";
    nativePhoneNumber = tm.getLine1Number();
    return nativePhoneNumber;
}

19 Source : PhoneInfoUtils.java
with Apache License 2.0
from y1xian

@SuppressLint({ "MissingPermission", "HardwareIds" })
public static String getPhoneInfo() {
    TelephonyManager tm = (TelephonyManager) AppUtils.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    StringBuffer sb = new StringBuffer();
    sb.append(" \nLine1Number = " + tm.getLine1Number());
    // 移动运营商编号
    sb.append(" \nNetworkOperator = " + tm.getNetworkOperator());
    // 移动运营商名称
    sb.append(" \nNetworkOperatorName = " + tm.getNetworkOperatorName());
    sb.append(" \nSimCountryIso = " + tm.getSimCountryIso());
    sb.append(" \nSimOperator = " + tm.getSimOperator());
    sb.append(" \nSimOperatorName = " + tm.getSimOperatorName());
    sb.append(" \nSimSerialNumber = " + tm.getSimSerialNumber());
    sb.append(" \nSubscriberId(IMSI) = " + tm.getSubscriberId());
    return sb.toString();
}

19 Source : MyCallReceiver.java
with Apache License 2.0
from xietiantian

/**
 * Handle the Phone call related BroadcastActions
 * <action android:name="android.intent.action.PHONE_STATE" />
 * <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
 */
public clreplaced MyCallReceiver extends BroadcastReceiver {

    public MyCallReceiver() {
    }

    static TelephonyManager manager;

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("tiantianCallRecorder", "MyCallReceiver.onReceive ");
        if (!AppPreferences.getInstance(context).isRecordingEnabled()) {
            removeListener();
            return;
        }
        if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction())) {
            if (!AppPreferences.getInstance(context).isRecordingOutgoingEnabled()) {
                removeListener();
                return;
            }
            PhoneListener.getInstance(context).setOutgoing(intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER));
        } else {
            if (!AppPreferences.getInstance(context).isRecordingIncomingEnabled()) {
                removeListener();
                return;
            }
        }
        // Start Listening to the call....
        if (null == manager) {
            manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        }
        if (null != manager)
            manager.listen(PhoneListener.getInstance(context), PhoneStateListener.LISTEN_CALL_STATE);
    }

    private void removeListener() {
        if (null != manager) {
            if (PhoneListener.hasInstance())
                manager.listen(PhoneListener.getInstance(null), PhoneStateListener.LISTEN_NONE);
        }
    }
}

19 Source : ServiceRequirementProvider.java
with GNU General Public License v3.0
from XecureIT

public clreplaced ServiceRequirementProvider implements RequirementProvider {

    private final TelephonyManager telephonyManager;

    private final ServiceStateListener serviceStateListener;

    private final AtomicBoolean listeningForServiceState;

    private RequirementListener requirementListener;

    public ServiceRequirementProvider(Context context) {
        this.telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        this.serviceStateListener = new ServiceStateListener();
        this.listeningForServiceState = new AtomicBoolean(false);
    }

    @Override
    public void setListener(RequirementListener requirementListener) {
        this.requirementListener = requirementListener;
    }

    public void start() {
        if (listeningForServiceState.compareAndSet(false, true)) {
            this.telephonyManager.listen(serviceStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
        }
    }

    private void handleInService() {
        if (listeningForServiceState.compareAndSet(true, false)) {
            this.telephonyManager.listen(serviceStateListener, PhoneStateListener.LISTEN_NONE);
        }
        if (requirementListener != null) {
            requirementListener.onRequirementStatusChanged();
        }
    }

    private clreplaced ServiceStateListener extends PhoneStateListener {

        @Override
        public void onServiceStateChanged(ServiceState serviceState) {
            if (serviceState.getState() == ServiceState.STATE_IN_SERVICE) {
                handleInService();
            }
        }
    }
}

19 Source : SubscriptionManager.java
with Apache License 2.0
from WrBug

private int getSubIdForPhoneAccount(final TelephonyManager tm, final PhoneAccount account) {
    try {
        return (int) XposedHelpers.callMethod(tm, "getSubIdForPhoneAccount", account);
    } catch (Throwable t) {
        XposedBridge.log(t);
        return -1;
    }
}

19 Source : PPureData.java
with GNU General Public License v3.0
from victordiaz

private void initSystemServices() {
    TelephonyManager telephonyManager = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
    telephonyManager.listen(new PhoneStateListener() {

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            if (state == TelephonyManager.CALL_STATE_IDLE)
                startAudio();
            else
                stopAudio();
        }
    }, PhoneStateListener.LISTEN_CALL_STATE);
}

19 Source : PhoneUtils.java
with Apache License 2.0
from tianshaojie

/**
 * Return whether the device is phone.
 *
 * @return {@code true}: yes<br>{@code false}: no
 */
public static boolean isPhone() {
    TelephonyManager tm = getTelephonyManager();
    return tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}

19 Source : PhoneUtils.java
with Apache License 2.0
from tianshaojie

/**
 * Return the sim operator using mnc.
 *
 * @return the sim operator
 */
public static String getSimOperatorByMnc() {
    TelephonyManager tm = getTelephonyManager();
    String operator = tm.getSimOperator();
    if (operator == null)
        return "";
    switch(operator) {
        case "46000":
        case "46002":
        case "46007":
        case "46020":
            return "中国移动";
        case "46001":
        case "46006":
        case "46009":
            return "中国联通";
        case "46003":
        case "46005":
        case "46011":
            return "中国电信";
        default:
            return operator;
    }
}

19 Source : PhoneUtils.java
with Apache License 2.0
from tianshaojie

/**
 * Return the sim operator name.
 *
 * @return the sim operator name
 */
public static String getSimOperatorName() {
    TelephonyManager tm = getTelephonyManager();
    return tm.getSimOperatorName();
}

19 Source : PhoneUtils.java
with Apache License 2.0
from tianshaojie

/**
 * Return whether sim card state is ready.
 *
 * @return {@code true}: yes<br>{@code false}: no
 */
public static boolean isSimCardReady() {
    TelephonyManager tm = getTelephonyManager();
    return tm.getSimState() == TelephonyManager.SIM_STATE_READY;
}

19 Source : LocaleServiceImpl.java
with GNU Affero General Public License v3.0
from threema-ch

public String getCountryIsoCode() {
    if (this.countryIsoCode == null) {
        try {
            TelephonyManager tm = (TelephonyManager) this.context.getSystemService(Context.TELEPHONY_SERVICE);
            this.countryIsoCode = tm.getSimCountryIso().toUpperCase();
        } catch (Exception x) {
        // do nothing
        // is TELEPHONY_SERVICE disabled?s
        }
        if (this.countryIsoCode == null || this.countryIsoCode.length() == 0) {
            this.countryIsoCode = Locale.getDefault().getCountry();
        }
    }
    return this.countryIsoCode;
}

19 Source : ussd_request_callback.java
with BSD 3-Clause "New" or "Revised" License
from telegram-sms

@Override
public void onReceiveUssdResponse(TelephonyManager telephonyManager, String request, CharSequence response) {
    super.onReceiveUssdResponse(telephonyManager, request, response);
    String message = message_header + "\n" + context.getString(R.string.request) + request + "\n" + context.getString(R.string.content) + response.toString();
    network_progress_handle(message);
}

19 Source : ussd_request_callback.java
with BSD 3-Clause "New" or "Revised" License
from telegram-sms

@Override
public void onReceiveUssdResponseFailed(TelephonyManager telephonyManager, String request, int failureCode) {
    super.onReceiveUssdResponseFailed(telephonyManager, request, failureCode);
    String message = message_header + "\n" + context.getString(R.string.request) + request + "\n" + context.getString(R.string.error_message) + get_error_code_string(failureCode);
    network_progress_handle(message);
}

19 Source : Main4Activity.java
with Apache License 2.0
from stytooldex

private void saveFeedbackMsg(String msg) {
    TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
    String imei = "" + telephonyManager.getDeviceId();
    // String last6chars = imei.remove(0,imei.length-6);
    int n = 4;
    final String b = imei.substring(imei.length() - n, imei.length());
    // final int count = Integer.parseInt(b) + 36;
    xp feedback = new xp();
    feedback.setContent(b + "; " + msg);
    feedback.save(new SaveListener<String>() {

        @Override
        public void done(String objectId, BmobException e) {
            if (e == null) {
            } else {
            }
        }
    });
}

19 Source : RegisterActivity.java
with MIT License
from stytooldex

private void register() {
    String username = ediusername.getText().toString().trim();
    String email = ediemail.getText().toString().trim();
    String preplacedword = edipreplacedword.getText().toString().trim();
    String preplacedwordTwo = edipreplacedwordTwo.getText().toString().trim();
    ediusername.setError(null);
    ediemail.setError(null);
    edipreplacedword.setError(null);
    edipreplacedwordTwo.setError(null);
    if (TextUtils.isEmpty(username)) {
        ediusername.setError("用户名不能为空");
        return;
    }
    if (TextUtils.isEmpty(email)) {
        ediemail.setError("请输入邮箱");
        return;
    }
    if (!isEmailValidate(email)) {
        ediemail.setError("这不是一个有效的邮箱");
        return;
    }
    if (TextUtils.isEmpty(preplacedword)) {
        edipreplacedword.setError("密码不能为空");
        return;
    }
    if (TextUtils.isEmpty(preplacedwordTwo)) {
        edipreplacedwordTwo.setError("请再次输入一次密码");
        return;
    }
    if (!preplacedword.equals(preplacedwordTwo)) {
        new AlertDialog.Builder(getActivity()).setMessage("两次输入的密码不一致").create().show();
        return;
    }
    if (!isPreplacedwordValidate(preplacedword)) {
        new AlertDialog.Builder(getActivity()).setMessage("密码长度过短,最小7位以上").create().show();
        return;
    }
    TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(getActivity().TELEPHONY_SERVICE);
    final MyUser user = new MyUser();
    user.setUsername(username);
    user.setPreplacedword(preplacedword);
    user.setEmail(email);
    user.setScore(10);
    user.setSex(1);
    user.setAddress("不激活");
    user.setHol(tm.getDeviceId());
    user.setid(getHostIP());
    user.signUp(getActivity(), new SaveListener() {

        @Override
        public void onSuccess() {
            bindUserIdAndDriverice(user);
            Toast.makeText(getActivity(), "注册成功", Toast.LENGTH_SHORT).show();
            getActivity().sendBroadcast(new Intent(Constant.ACTION_REGISTER_SUCCESS_FINISH));
        }

        @Override
        public void onFailure(int i, String s) {
            Toast.makeText(getActivity(), "注册失败\n日志:" + i, Toast.LENGTH_SHORT).show();
        }
    });
}

19 Source : Depr_CellsInfoDataCollector.java
with MIT License
from STRCWearlab

public clreplaced Depr_CellsInfoDataCollector extends AbstractDataCollector {

    private static final String TAG = Depr_CellsInfoDataCollector.clreplaced.getSimpleName();

    private CustomLogger logger = null;

    // The telephony manager reference
    private TelephonyManager mTelephonyManager = null;

    // Listener clreplaced for monitoring changes in telephony states
    private CellInfoListener mCellInfoListener = null;

    // Timer to manage specific sampling rates
    private Handler mTimerHandler = null;

    private Runnable mTimerRunnable = null;

    public Depr_CellsInfoDataCollector(Context context, String sessionName, String sensorName, long nanosOffset, int logFileMaxSize) {
        mSensorName = sensorName;
        String path = sessionName + File.separator + mSensorName + "_" + sessionName;
        logger = new CustomLogger(context, path, sessionName, mSensorName, "txt", false, mNanosOffset, logFileMaxSize);
        // Object to provide access to information about the telephony services on the device
        mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        // Offset to match timestamps both in master and slaves devices
        mNanosOffset = nanosOffset;
        mCellInfoListener = new CellInfoListener();
    }

    @Override
    public void start() {
        Log.i(TAG, "start:: Starting listener for sensor: " + getSensorName());
        logger.start();
        mTelephonyManager.listen(mCellInfoListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    }

    @Override
    public void stop() {
        Log.i(TAG, "stop:: Stopping listener for sensor " + getSensorName());
        mTelephonyManager.listen(mCellInfoListener, PhoneStateListener.LISTEN_NONE);
        logger.stop();
    }

    @Override
    public void haltAndRestartLogging() {
        logger.stop();
        logger.resetByteCounter();
        logger.start();
    }

    @Override
    public void updateNanosOffset(long nanosOffset) {
        mNanosOffset = nanosOffset;
    }

    private static String networkTypeGeneral(int networkType) {
        switch(networkType) {
            case TelephonyManager.NETWORK_TYPE_EHRPD:
            case TelephonyManager.NETWORK_TYPE_LTE:
                return "4G";
            case TelephonyManager.NETWORK_TYPE_HSDPA:
            case TelephonyManager.NETWORK_TYPE_HSPA:
            case TelephonyManager.NETWORK_TYPE_HSPAP:
            case TelephonyManager.NETWORK_TYPE_HSUPA:
            case TelephonyManager.NETWORK_TYPE_UMTS:
                return "3G";
            case TelephonyManager.NETWORK_TYPE_EDGE:
            case TelephonyManager.NETWORK_TYPE_GPRS:
            case TelephonyManager.NETWORK_TYPE_IDEN:
                return "2G";
            case TelephonyManager.NETWORK_TYPE_1xRTT:
            case TelephonyManager.NETWORK_TYPE_CDMA:
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
            case TelephonyManager.NETWORK_TYPE_EVDO_B:
                return "CDMA";
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            default:
                return "Unknown";
        }
    }

    private String getCellInfoString(SignalStrength signalStrength) {
        // Timestamp in system nanoseconds since boot, including time spent in sleep.
        long nanoTime = SystemClock.elapsedRealtimeNanos() + mNanosOffset;
        // System local time in millis
        long currentMillis = (new Date()).getTime();
        String message = String.format("%s", currentMillis) + ";" + String.format("%s", nanoTime) + ";" + String.format("%s", mNanosOffset) + ";";
        CellLocation cell = mTelephonyManager.getCellLocation();
        if (cell instanceof GsmCellLocation) {
            int lac, cid, dbm;
            lac = ((GsmCellLocation) cell).getLac();
            cid = ((GsmCellLocation) cell).getCid();
            String generalNetworkType = networkTypeGeneral(mTelephonyManager.getNetworkType());
            // "SignalStrength: mGsmSignalStrength mGsmBitErrorRate mCdmaDbm mCdmaEcio mEvdoDbm
            // mEvdoEcio mEvdoSnr mLteSignalStrength mLteRsrp mLteRsrq mLteRssnr mLteCqi
            // (isGsm ? "gsm|lte" : "cdma"));
            String ssignal = signalStrength.toString();
            String[] parts = ssignal.split(" ");
            // If the signal is not the right signal in db (a signal below -2) fallback
            // Fallbacks will be triggered whenever generalNetworkType changes
            if (generalNetworkType.equals("4G")) {
                dbm = Integer.parseInt(parts[11]);
                if (dbm >= -2) {
                    if (Integer.parseInt(parts[3]) < -2) {
                        dbm = Integer.parseInt(parts[3]);
                    } else {
                        dbm = signalStrength.getGsmSignalStrength();
                    }
                }
            } else if (generalNetworkType.equals("3G")) {
                dbm = Integer.parseInt(parts[3]);
                if (dbm >= -2) {
                    if (Integer.parseInt(parts[11]) < -2) {
                        dbm = Integer.parseInt(parts[11]);
                    } else {
                        dbm = signalStrength.getGsmSignalStrength();
                    }
                }
            } else {
                dbm = signalStrength.getGsmSignalStrength();
                if (dbm >= -2) {
                    if (Integer.parseInt(parts[3]) < -2) {
                        dbm = Integer.parseInt(parts[3]);
                    } else {
                        dbm = Integer.parseInt(parts[11]);
                    }
                }
            }
            // Returns the numeric name (MCC+MNC) of current registered operator.
            String mccMnc = mTelephonyManager.getNetworkOperator();
            String mcc, mnc;
            if (mccMnc != null && mccMnc.length() >= 4) {
                mcc = mccMnc.substring(0, 3);
                mnc = mccMnc.substring(3);
            } else {
                mcc = "NaN";
                mnc = "NaN";
            }
            if (dbm < -2) {
                message += mTelephonyManager.getNetworkType() + ";" + cid + ";" + lac + ";" + dbm + ";" + mcc + ";" + mnc;
            } else {
                message += mTelephonyManager.getNetworkType() + ";" + cid + ";" + lac + ";" + "NaN" + ";" + mcc + ";" + mnc;
            }
        }
        // // Deprecated behavior, not collecting data
        // List<NeighboringCellInfo> neighboringCellInfoList = mTelephonyManager.getNeighboringCellInfo();
        // for (NeighboringCellInfo neighboringCellInfo : neighboringCellInfoList){
        // }
        return message;
    }

    private void logCellInfo(String message) {
        if (logger != null) {
            Log.d(TAG, message);
            logger.log(message);
            logger.log(System.lineSeparator());
        }
    }

    /**
     * A listener clreplaced for monitoring changes in specific telephony states on the device,
     * including service state, signal strength, message waiting indicator (voicemail), and others.
     */
    private clreplaced CellInfoListener extends PhoneStateListener {

        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            super.onSignalStrengthsChanged(signalStrength);
            logCellInfo(getCellInfoString(signalStrength));
        }
    }
}

19 Source : CellsInfoDataCollector.java
with MIT License
from STRCWearlab

public clreplaced CellsInfoDataCollector extends AbstractDataCollector {

    private static final String TAG = CellsInfoDataCollector.clreplaced.getSimpleName();

    private CustomLogger logger = null;

    private int mSamplingPeriodUs;

    // The telephony manager reference
    private TelephonyManager mTelephonyManager = null;

    // Listener clreplaced for monitoring changes in telephony states
    private CellInfoListener mCellInfoListener = null;

    // Timer to manage specific sampling rates
    private Handler mTimerHandler = null;

    private Runnable mTimerRunnable = null;

    public CellsInfoDataCollector(Context context, String sessionName, String sensorName, int samplingPeriodUs, long nanosOffset, int logFileMaxSize) {
        mSensorName = sensorName;
        String path = sessionName + File.separator + mSensorName + "_" + sessionName;
        // Offset to match timestamps both in master and slaves devices
        mNanosOffset = nanosOffset;
        logger = new CustomLogger(context, path, sessionName, mSensorName, "txt", false, mNanosOffset, logFileMaxSize);
        mSamplingPeriodUs = samplingPeriodUs;
        // Object to provide access to information about the telephony services on the device
        mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        /**
         * If the the sampling rate is 0 (default), a listener is registered  for monitoring changes
         * in specific telephony states on the device. If there is a sampling rate defined by the
         * user (sampling rate greater than zero) a timer is defined to check the device state at
         * specific intervals.
         */
        if (mSamplingPeriodUs > 0) {
            mTimerHandler = new Handler();
            mTimerRunnable = new Runnable() {

                @Override
                public void run() {
                    // Returns all observed cell information from all radios on the device including the primary and neighboring cells.
                    logCellInfo(mTelephonyManager.getAllCellInfo());
                    int millis = 1000 / mSamplingPeriodUs;
                    mTimerHandler.postDelayed(this, millis);
                }
            };
        } else {
            mCellInfoListener = new CellInfoListener();
        }
    }

    private void logCellInfo(List<CellInfo> cellInfo) {
        if (logger != null) {
            String message = getCellInfoString(cellInfo);
            logger.log(message);
            Log.d(TAG, message);
            logger.log(System.lineSeparator());
        }
    }

    @Override
    public void start() {
        Log.i(TAG, "start:: Starting listener for sensor: " + getSensorName());
        logger.start();
        if (mCellInfoListener != null) {
            mTelephonyManager.listen(mCellInfoListener, PhoneStateListener.LISTEN_CELL_INFO | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_CELL_LOCATION);
        } else {
            mTimerHandler.postDelayed(mTimerRunnable, 0);
        }
    }

    @Override
    public void stop() {
        Log.i(TAG, "stop:: Stopping listener for sensor " + getSensorName());
        if (mCellInfoListener != null) {
            mTelephonyManager.listen(mCellInfoListener, PhoneStateListener.LISTEN_NONE);
        } else {
            mTimerHandler.removeCallbacks(mTimerRunnable);
        }
        logger.stop();
    }

    @Override
    public void haltAndRestartLogging() {
        logger.stop();
        logger.resetByteCounter();
        logger.start();
    }

    @Override
    public void updateNanosOffset(long nanosOffset) {
        mNanosOffset = nanosOffset;
    }

    /**
     * A listener clreplaced for monitoring changes in specific telephony states on the device,
     * including service state, signal strength, message waiting indicator (voicemail), and others.
     */
    private clreplaced CellInfoListener extends PhoneStateListener {

        @Override
        public void onCellInfoChanged(List<CellInfo> cellInfo) {
            super.onCellInfoChanged(cellInfo);
            if (cellInfo == null)
                return;
            logCellInfo(cellInfo);
        }

        @Override
        public void onCellLocationChanged(CellLocation location) {
            super.onCellLocationChanged(location);
            // getAllCellInfo() returns all observed cell information from all radios on the device including the primary and neighboring cells
            // This is preferred over using getCellLocation although for older devices this may return null in which case getCellLocation should be called.
            logCellInfo(mTelephonyManager.getAllCellInfo());
        }

        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            super.onSignalStrengthsChanged(signalStrength);
            // getAllCellInfo() returns all observed cell information from all radios on the device including the primary and neighboring cells
            // This is preferred over using getCellLocation although for older devices this may return null in which case getCellLocation should be called.
            logCellInfo(mTelephonyManager.getAllCellInfo());
        }
    }

    private String getCellInfoString(List<CellInfo> cellsInfo) {
        // Timestamp in system nanoseconds since boot, including time spent in sleep.
        long nanoTime = SystemClock.elapsedRealtimeNanos() + mNanosOffset;
        // System local time in millis
        long currentMillis = (new Date()).getTime();
        String message = String.format("%s", currentMillis) + ";" + String.format("%s", nanoTime) + ";" + String.format("%s", mNanosOffset) + ";" + Integer.toString(cellsInfo.size());
        // The list can include one or more CellInfoGsm, CellInfoCdma, CellInfoLte, and CellInfoWcdma objects, in any combination.
        for (final CellInfo cellInfo : cellsInfo) {
            if (cellInfo instanceof CellInfoGsm) {
                // True if this cell is registered to the mobile network.
                // 0, 1 or more CellInfo objects may return isRegistered() true.
                int isRegistered = (cellInfo.isRegistered()) ? 1 : 0;
                final CellSignalStrengthGsm gsmStrength = ((CellInfoGsm) cellInfo).getCellSignalStrength();
                // Get the signal level as an asu value between 0..31, 99 is unknown Asu is calculated based on 3GPP RSRP.
                int asuLevel = gsmStrength.getAsuLevel();
                // Get the signal strength as dBm
                int dBm = gsmStrength.getDbm();
                // Get signal level as an int from 0..4
                int level = gsmStrength.getLevel();
                final CellIdenreplacedyGsm gsmId = ((CellInfoGsm) cellInfo).getCellIdenreplacedy();
                // CID Either 16-bit GSM Cell Idenreplacedy described in TS 27.007, 0..65535, Integer.MAX_VALUE if unknown
                int cid = gsmId.getCid();
                // 16-bit Location Area Code, 0..65535, Integer.MAX_VALUE if unknown
                int lac = gsmId.getLac();
                // 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown
                int mcc = gsmId.getMcc();
                // 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown
                int mnc = gsmId.getMnc();
                message += ";GSM;" + isRegistered + ";" + cid + ";" + lac + ";" + mcc + ";" + mnc + ";" + asuLevel + ";" + dBm + ";" + level;
            } else if (cellInfo instanceof CellInfoCdma) {
                // True if this cell is registered to the mobile network.
                // 0, 1 or more CellInfo objects may return isRegistered() true.
                int isRegistered = (cellInfo.isRegistered()) ? 1 : 0;
                final CellSignalStrengthCdma cdmaStength = ((CellInfoCdma) cellInfo).getCellSignalStrength();
                // Get the signal level as an asu value between 0..97, 99 is unknown
                int asuLevel = cdmaStength.getAsuLevel();
                // Get the CDMA RSSI value in dBm
                int cdmaDbm = cdmaStength.getCdmaDbm();
                // Get the CDMA Ec/Io value in dB*10
                int cdmaEcio = cdmaStength.getCdmaEcio();
                // Get cdma as level 0..4
                int cdmaLevel = cdmaStength.getCdmaLevel();
                // Get the signal strength as dBm
                int dBm = cdmaStength.getDbm();
                // Get the EVDO RSSI value in dBm
                int evdoDbm = cdmaStength.getEvdoDbm();
                // Get the EVDO Ec/Io value in dB*10
                int evdoEcio = cdmaStength.getEvdoEcio();
                // Get Evdo as level 0..4
                int evdoLevel = cdmaStength.getEvdoLevel();
                // Get the signal to noise ratio.
                int evdoSnr = cdmaStength.getEvdoSnr();
                // Get signal level as an int from 0..4
                int level = cdmaStength.getLevel();
                final CellIdenreplacedyCdma cdmaId = ((CellInfoCdma) cellInfo).getCellIdenreplacedy();
                // Base Station Id 0..65535, Integer.MAX_VALUE if unknown
                int basestationId = cdmaId.getBasestationId();
                // Base station lareplacedude, which is a decimal number as specified in 3GPP2 C.S0005-A v6.0.
                // It is represented in units of 0.25 seconds and ranges from -1296000 to 1296000, both
                // values inclusive (corresponding to a range of -90 to +90 degrees). Integer.MAX_VALUE if unknown.
                int lareplacedude = cdmaId.getLareplacedude();
                // Base station longitude, which is a decimal number as specified in 3GPP2 C.S0005-A v6.0.
                // It is represented in units of 0.25 seconds and ranges from -2592000 to 2592000, both
                // values inclusive (corresponding to a range of -180 to +180 degrees). Integer.MAX_VALUE if unknown.
                int longitude = cdmaId.getLongitude();
                // Network Id 0..65535, Integer.MAX_VALUE if unknown
                int networkId = cdmaId.getNetworkId();
                // System Id 0..32767, Integer.MAX_VALUE if unknown
                int systemId = cdmaId.getSystemId();
                message += ";CDMA;" + isRegistered + ";" + basestationId + ";" + lareplacedude + ";" + longitude + ";" + networkId + ";" + systemId + ";" + asuLevel + ";" + cdmaDbm + ";" + cdmaEcio + ";" + cdmaLevel + ";" + dBm + ";" + evdoDbm + ";" + evdoEcio + ";" + evdoLevel + ";" + evdoSnr + ";" + level;
            } else if (cellInfo instanceof CellInfoLte) {
                // True if this cell is registered to the mobile network.
                // 0, 1 or more CellInfo objects may return isRegistered() true.
                int isRegistered = (cellInfo.isRegistered()) ? 1 : 0;
                final CellSignalStrengthLte lteStrength = ((CellInfoLte) cellInfo).getCellSignalStrength();
                // Get the LTE signal level as an asu value between 0..97, 99 is unknown Asu is calculated based on 3GPP RSRP.
                // Represents a normalized version of the signal strength as dBm
                int asuLevel = lteStrength.getAsuLevel();
                // Get the signal strength as dBm
                // Returns RSRP – Reference Signal Received Power
                int dBm = lteStrength.getDbm();
                // Get signal level as an int from 0..4
                int level = lteStrength.getLevel();
                final CellIdenreplacedyLte lteId = ((CellInfoLte) cellInfo).getCellIdenreplacedy();
                // 28-bit Cell Idenreplacedy, Integer.MAX_VALUE if unknown
                int ci = lteId.getCi();
                // 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown
                int mcc = lteId.getMcc();
                // 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown
                int mnc = lteId.getMnc();
                // Physical Cell Id 0..503, Integer.MAX_VALUE if unknown
                int pci = lteId.getPci();
                // 16-bit Tracking Area Code, Integer.MAX_VALUE if unknown
                int tac = lteId.getTac();
                message += ";LTE;" + isRegistered + ";" + ci + ";" + mcc + ";" + mnc + ";" + pci + ";" + tac + ";" + asuLevel + ";" + dBm + ";" + level;
            // 13 129108338 114 -1
            // LTE;129108338;234;10;384;144;39;-101;3
            } else if (cellInfo instanceof CellInfoWcdma) {
                // True if this cell is registered to the mobile network.
                // 0, 1 or more CellInfo objects may return isRegistered() true.
                int isRegistered = (cellInfo.isRegistered()) ? 1 : 0;
                final CellSignalStrengthWcdma wcdmaStrength = ((CellInfoWcdma) cellInfo).getCellSignalStrength();
                // Get the signal level as an asu value between 0..31, 99 is unknown Asu is calculated based on 3GPP RSRP.
                int asuLevel = wcdmaStrength.getAsuLevel();
                // Get the signal strength as dBm
                int dBm = wcdmaStrength.getDbm();
                // Get signal level as an int from 0..4
                int level = wcdmaStrength.getLevel();
                final CellIdenreplacedyWcdma wcdmaId = ((CellInfoWcdma) cellInfo).getCellIdenreplacedy();
                // CID 28-bit UMTS Cell Idenreplacedy described in TS 25.331, 0..268435455, Integer.MAX_VALUE if unknown
                int cid = wcdmaId.getCid();
                // 16-bit Location Area Code, 0..65535, Integer.MAX_VALUE if unknown
                int lac = wcdmaId.getLac();
                // 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown
                int mcc = wcdmaId.getMcc();
                // 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown
                int mnc = wcdmaId.getMnc();
                // 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511, Integer.MAX_VALUE if unknown
                int psc = wcdmaId.getPsc();
                message += ";WCDMA;" + isRegistered + ";" + cid + ";" + lac + ";" + mcc + ";" + mnc + ";" + psc + ";" + asuLevel + ";" + dBm + ";" + level;
            } else {
                Log.e(TAG, "Unknown type of cell signal");
            }
        }
        return message;
    }
}

19 Source : AudioPlayer.java
with Apache License 2.0
from squareboat

private boolean hreplacedIM() {
    TelephonyManager manager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    return manager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}

19 Source : NetworkUtils.java
with Apache License 2.0
from smuyyh

/**
 * 获取网络运营商名称
 * <p>中国移动、如中国联通、中国电信</p>
 *
 * @return 运营商名称
 */
public static String getNetworkOperatorName() {
    TelephonyManager tm = (TelephonyManager) Global.getApplication().getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null ? tm.getNetworkOperatorName() : null;
}

19 Source : AppManager.java
with Apache License 2.0
from smartyuge

public static String getIMEI() {
    try {
        TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        String IMEI_Number = telephonyManager.getDeviceId();
        if ((IMEI_Number != null) && (IMEI_Number.length() > 0)) {
            return IMEI_Number;
        }
    } catch (Exception localException) {
        localException.printStackTrace();
    }
    return null;
}

19 Source : SDDeviceUtil.java
with Apache License 2.0
from SiberiaDante

/**
 * 获取Sim卡运营商名称
 * <p>中国移动、如中国联通、中国电信</p>
 *
 * @return sim卡运营商名称
 */
public static String getSimOperatorName() {
    TelephonyManager tm = (TelephonyManager) SDAndroidLib.getContext().getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null ? tm.getSimOperatorName() : null;
}

19 Source : SDDeviceUtil.java
with Apache License 2.0
from SiberiaDante

/**
 * 判断设备是否是手机
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isPhone() {
    TelephonyManager tm = (TelephonyManager) SDAndroidLib.getContext().getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}

19 Source : SDDeviceUtil.java
with Apache License 2.0
from SiberiaDante

/**
 * 获取Sim卡运营商名称
 * <p>中国移动、如中国联通、中国电信</p>
 *
 * @return 移动网络运营商名称
 */
public static String getSimOperatorByMnc() {
    TelephonyManager tm = (TelephonyManager) SDAndroidLib.getContext().getSystemService(Context.TELEPHONY_SERVICE);
    String operator = tm != null ? tm.getSimOperator() : null;
    if (operator == null)
        return null;
    switch(operator) {
        case "46000":
        case "46002":
        case "46007":
            return "中国移动";
        case "46001":
            return "中国联通";
        case "46003":
            return "中国电信";
        default:
            return operator;
    }
}

19 Source : SDDeviceUtil.java
with Apache License 2.0
from SiberiaDante

/**
 * 获取终端类型
 *
 * @return 手机制式
 * <ul>
 * <li>{@link TelephonyManager#PHONE_TYPE_NONE } : 0 手机制式未知</li>
 * <li>{@link TelephonyManager#PHONE_TYPE_GSM  } : 1 手机制式为GSM,移动和联通</li>
 * <li>{@link TelephonyManager#PHONE_TYPE_CDMA } : 2 手机制式为CDMA,电信</li>
 * <li>{@link TelephonyManager#PHONE_TYPE_SIP  } : 3</li>
 * </ul>
 */
public static int getPhoneType() {
    TelephonyManager tm = (TelephonyManager) SDAndroidLib.getContext().getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null ? tm.getPhoneType() : -1;
}

19 Source : SDDeviceUtil.java
with Apache License 2.0
from SiberiaDante

/**
 * 判断sim卡是否准备好
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isSimCardReady() {
    TelephonyManager tm = (TelephonyManager) SDAndroidLib.getContext().getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null && tm.getSimState() == TelephonyManager.SIM_STATE_READY;
}

19 Source : DeviceUtils.java
with Apache License 2.0
from Shouheng88

public static String getSimOperatorName() {
    TelephonyManager tm = (TelephonyManager) UtilsApp.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    // noinspection ConstantConditions
    return tm.getSimOperatorName();
}

19 Source : DeviceUtils.java
with Apache License 2.0
from Shouheng88

public static boolean isPhone() {
    TelephonyManager tm = (TelephonyManager) UtilsApp.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    // noinspection ConstantConditions
    return tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}

19 Source : DeviceUtils.java
with Apache License 2.0
from Shouheng88

public static String getSimOperatorByMnc() {
    TelephonyManager tm = (TelephonyManager) UtilsApp.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    // noinspection ConstantConditions
    String operator = tm.getSimOperator();
    if (operator == null)
        return "";
    switch(operator) {
        case "46000":
        case "46002":
        case "46007":
        case "46020":
            return "中国移动";
        case "46001":
        case "46006":
        case "46009":
            return "中国联通";
        case "46003":
        case "46005":
        case "46011":
            return "中国电信";
        default:
            return operator;
    }
}

19 Source : DeviceUtils.java
with Apache License 2.0
from Shouheng88

public static boolean isSimCardReady() {
    TelephonyManager tm = (TelephonyManager) UtilsApp.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    // noinspection ConstantConditions
    return tm.getSimState() == TelephonyManager.SIM_STATE_READY;
}

19 Source : MyPhonStateService.java
with GNU Affero General Public License v3.0
from RooyeKhat-Media

public clreplaced MyPhonStateService extends BroadcastReceiver {

    TelephonyManager telephony;

    /**
     * use when start or finish ringing
     */
    public void onReceive(Context context, Intent intent) {
        MyPhoneStateListener phoneListener = new MyPhoneStateListener();
        telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
    }

    public void onDestroy() {
        telephony.listen(null, PhoneStateListener.LISTEN_NONE);
    }
}

19 Source : AndroidTelephonyManagerBridge.java
with BSD 3-Clause "New" or "Revised" License
from ridi

/**
 * Returns the MCC+MNC (mobile country code + mobile network code) as
 * the numeric name of the current SIM operator.
 */
public String getSimOperator() {
    if (mSimOperator == null) {
        TelephonyManager telephonyManager = getTelephonyManager();
        if (telephonyManager == null) {
            return "";
        }
        mSimOperator = telephonyManager.getSimOperator();
    }
    return mSimOperator;
}

19 Source : AndroidTelephonyManagerBridge.java
with BSD 3-Clause "New" or "Revised" License
from ridi

private static AndroidTelephonyManagerBridge create() {
    AndroidTelephonyManagerBridge instance = new AndroidTelephonyManagerBridge();
    ThreadUtils.runOnUiThread(() -> {
        TelephonyManager telephonyManager = getTelephonyManager();
        if (telephonyManager != null) {
            instance.listenTelephonyServiceState(telephonyManager);
        }
    });
    return instance;
}

19 Source : AndroidTelephonyManagerBridge.java
with BSD 3-Clause "New" or "Revised" License
from ridi

/**
 * Returns the MCC+MNC (mobile country code + mobile network code) as
 * the numeric name of the current registered operator.
 */
public String getNetworkOperator() {
    if (mNetworkOperator == null) {
        TelephonyManager telephonyManager = getTelephonyManager();
        if (telephonyManager == null) {
            return "";
        }
        mNetworkOperator = telephonyManager.getNetworkOperator();
    }
    return mNetworkOperator;
}

19 Source : AndroidTelephonyManagerBridge.java
with BSD 3-Clause "New" or "Revised" License
from ridi

/**
 * Returns the ISO country code equivalent of the current MCC.
 */
public String getNetworkCountryIso() {
    if (mNetworkCountryIso == null) {
        TelephonyManager telephonyManager = getTelephonyManager();
        if (telephonyManager == null) {
            return "";
        }
        mNetworkCountryIso = telephonyManager.getNetworkCountryIso();
    }
    return mNetworkCountryIso;
}

19 Source : AndroidTelephonyManagerBridge.java
with BSD 3-Clause "New" or "Revised" License
from ridi

@MainThread
private void listenTelephonyServiceState(TelephonyManager telephonyManager) {
    ThreadUtils.replacedertOnUiThread();
    mListener = new Listener();
    telephonyManager.listen(mListener, PhoneStateListener.LISTEN_SERVICE_STATE);
}

19 Source : AndroidTelephonyManagerBridge.java
with BSD 3-Clause "New" or "Revised" License
from ridi

private void update(@CheckForNull TelephonyManager telephonyManager) {
    if (telephonyManager == null) {
        return;
    }
    mNetworkCountryIso = telephonyManager.getNetworkCountryIso();
    mNetworkOperator = telephonyManager.getNetworkOperator();
    mSimOperator = telephonyManager.getSimOperator();
}

19 Source : PhoneUtils.java
with BSD 2-Clause "Simplified" License
from pppscn

/**
 * 判断设备是否是手机
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isPhone() {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}

19 Source : PhoneUtils.java
with BSD 2-Clause "Simplified" License
from pppscn

/**
 * 判断sim卡是否准备好
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isSimCardReady() {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null && tm.getSimState() == TelephonyManager.SIM_STATE_READY;
}

19 Source : PhoneUtils.java
with BSD 2-Clause "Simplified" License
from pppscn

/**
 * 获取Sim卡序列号
 * <p>
 * Requires Permission:
 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
 *
 * @return 序列号
 */
public static String getSimSerialNumber() {
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String serialNumber = tm != null ? tm.getSimSerialNumber() : null;
        return serialNumber != null ? serialNumber : "";
    } catch (Exception e) {
    }
    return "";
}

19 Source : PhoneUtils.java
with BSD 2-Clause "Simplified" License
from pppscn

/**
 * 获取Sim卡的国家代码
 *
 * @return 国家代码
 */
public static String getSimCountryIso() {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null ? tm.getSimCountryIso() : null;
}

19 Source : PhoneUtils.java
with BSD 2-Clause "Simplified" License
from pppscn

/**
 * 获取Sim卡运营商名称
 * <p>中国移动、如中国联通、中国电信</p>
 *
 * @return sim卡运营商名称
 */
public static String getSimOperatorName() {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null ? tm.getSimOperatorName() : null;
}

19 Source : PhoneUtils.java
with BSD 2-Clause "Simplified" License
from pppscn

/**
 * 获取Sim卡运营商名称
 * <p>中国移动、如中国联通、中国电信</p>
 *
 * @return 移动网络运营商名称
 */
public static String getSimOperatorByMnc() {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String operator = tm != null ? tm.getSimOperator() : null;
    if (operator == null) {
        return null;
    }
    switch(operator) {
        case "46000":
        case "46002":
        case "46007":
            return "中国移动";
        case "46001":
            return "中国联通";
        case "46003":
            return "中国电信";
        default:
            return operator;
    }
}

19 Source : SystemUtil.java
with Apache License 2.0
from pinguo-sunjianfei

public static String getIMEI() {
    TelephonyManager tm = (TelephonyManager) gContext.getSystemService(Context.TELEPHONY_SERVICE);
    String imei = tm.getDeviceId();
    if (TextUtils.isEmpty(imei)) {
        imei = "";
    }
    return imei;
}

See More Examples