Search in sources :

Example 51 with TelephonyManager

use of android.telephony.TelephonyManager in project qksms by moezbhatti.

the class ApnUtils method getSimOperatorCodes.

public static String[] getSimOperatorCodes(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String simOperator = telephonyManager.getSimOperator();
    String[] mccmnc = new String[] { null, null };
    if (!TextUtils.isEmpty(simOperator)) {
        mccmnc[0] = simOperator.substring(0, 3);
        mccmnc[1] = simOperator.substring(3);
    }
    return mccmnc;
}
Also used : TelephonyManager(android.telephony.TelephonyManager)

Example 52 with TelephonyManager

use of android.telephony.TelephonyManager in project Signal-Android by WhisperSystems.

the class TelephonyUtil method getMccMnc.

public static String getMccMnc(final Context context) {
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    final int configMcc = context.getResources().getConfiguration().mcc;
    final int configMnc = context.getResources().getConfiguration().mnc;
    if (tm.getSimState() == TelephonyManager.SIM_STATE_READY) {
        Log.w(TAG, "Choosing MCC+MNC info from TelephonyManager.getSimOperator()");
        return tm.getSimOperator();
    } else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) {
        Log.w(TAG, "Choosing MCC+MNC info from TelephonyManager.getNetworkOperator()");
        return tm.getNetworkOperator();
    } else if (configMcc != 0 && configMnc != 0) {
        Log.w(TAG, "Choosing MCC+MNC info from current context's Configuration");
        return String.format("%03d%d", configMcc, configMnc == Configuration.MNC_ZERO ? 0 : configMnc);
    } else {
        return null;
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager)

Example 53 with TelephonyManager

use of android.telephony.TelephonyManager in project Klyph by jonathangerbaud.

the class Android method getDeviceUDID.

public static String getDeviceUDID(Context ctx) {
    final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    final String tmDevice, tmSerial, androidId;
    PackageManager pm = ctx.getPackageManager();
    int hasPerm = pm.checkPermission(android.Manifest.permission.READ_PHONE_STATE, ctx.getPackageName());
    if (hasPerm == PackageManager.PERMISSION_GRANTED) {
        tmDevice = "" + tm.getDeviceId();
        tmSerial = "" + tm.getSimSerialNumber();
    } else {
        tmDevice = Settings.Secure.ANDROID_ID;
        tmSerial = android.os.Build.SERIAL;
    }
    androidId = "" + android.provider.Settings.Secure.getString(ctx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    String deviceId = deviceUuid.toString();
    return deviceId;
}
Also used : PackageManager(android.content.pm.PackageManager) TelephonyManager(android.telephony.TelephonyManager) UUID(java.util.UUID)

Example 54 with TelephonyManager

use of android.telephony.TelephonyManager in project FastDev4Android by jiangqqlmj.

the class StrUtils method getIpBaseStation.

// 获取ip基站
public static String getIpBaseStation() {
    TelephonyManager telMgr = (TelephonyManager) FDApplication.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
    int cid = 0;
    int lac = 0;
    try {
        if (telMgr != null) {
            GsmCellLocation gc = (GsmCellLocation) telMgr.getCellLocation();
            if (null == gc) {
                return "0_0";
            }
            cid = gc.getCid();
            lac = gc.getLac();
        }
    } catch (Exception e) {
        if (telMgr != null) {
            CdmaCellLocation location = (CdmaCellLocation) telMgr.getCellLocation();
            if (null == location) {
                return "0_0";
            }
            lac = location.getNetworkId();
            cid = location.getBaseStationId();
            cid /= 16;
        }
    }
    return lac + "_" + cid;
}
Also used : TelephonyManager(android.telephony.TelephonyManager) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation) SuppressLint(android.annotation.SuppressLint) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 55 with TelephonyManager

use of android.telephony.TelephonyManager in project Klyph by jonathangerbaud.

the class Android method getDeviceUDID.

public static String getDeviceUDID(Context ctx) {
    final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    final String tmDevice, tmSerial, androidId;
    PackageManager pm = ctx.getPackageManager();
    int hasPerm = pm.checkPermission(android.Manifest.permission.READ_PHONE_STATE, ctx.getPackageName());
    if (hasPerm == PackageManager.PERMISSION_GRANTED) {
        tmDevice = "" + tm.getDeviceId();
        tmSerial = "" + tm.getSimSerialNumber();
    } else {
        tmDevice = Settings.Secure.ANDROID_ID;
        tmSerial = android.os.Build.SERIAL;
    }
    androidId = "" + android.provider.Settings.Secure.getString(ctx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    String deviceId = deviceUuid.toString();
    return deviceId;
}
Also used : PackageManager(android.content.pm.PackageManager) TelephonyManager(android.telephony.TelephonyManager) UUID(java.util.UUID)

Aggregations

TelephonyManager (android.telephony.TelephonyManager)294 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)20 SubscriptionManager (android.telephony.SubscriptionManager)20 Test (org.junit.Test)15 ConnectivityManager (android.net.ConnectivityManager)14 Context (android.content.Context)11 Intent (android.content.Intent)11 NetworkIdentity (android.net.NetworkIdentity)11 Method (java.lang.reflect.Method)11 GsmCellLocation (android.telephony.gsm.GsmCellLocation)10 PackageManager (android.content.pm.PackageManager)9 SubscriptionInfo (android.telephony.SubscriptionInfo)9 IntentFilter (android.content.IntentFilter)8 IOException (java.io.IOException)8 PackageInfo (android.content.pm.PackageInfo)7 ServiceState (android.telephony.ServiceState)7 NetworkPolicy (android.net.NetworkPolicy)6 WifiManager (android.net.wifi.WifiManager)6 DevicePolicyManagerInternal (android.app.admin.DevicePolicyManagerInternal)5 SharedPreferences (android.content.SharedPreferences)5