android.telephony.TelephonyManager类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(247)

本文整理了Java中android.telephony.TelephonyManager类的一些代码示例,展示了TelephonyManager类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TelephonyManager类的具体详情如下:
包路径:android.telephony.TelephonyManager
类名称:TelephonyManager

TelephonyManager介绍

[英]Stub class for compilation purpose. Created by Oasis on 2017/7/21.
[中]用于编译目的的存根类。绿洲于2017年7月21日创建。

代码示例

代码示例来源:origin: JessYanCoding/MVPArms

public static String getIMEI(Context context) {
  TelephonyManager tel = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  return tel.getDeviceId();
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

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

代码示例来源:origin: stackoverflow.com

public String getNetworkClass(Context context) {
  TelephonyManager mTelephonyManager = (TelephonyManager)
      context.getSystemService(Context.TELEPHONY_SERVICE);
  int networkType = mTelephonyManager.getNetworkType();
  switch (networkType) {
    case TelephonyManager.NETWORK_TYPE_GPRS:
    case TelephonyManager.NETWORK_TYPE_EDGE:
    case TelephonyManager.NETWORK_TYPE_CDMA:
    case TelephonyManager.NETWORK_TYPE_1xRTT:
    case TelephonyManager.NETWORK_TYPE_IDEN:
      return "2G";
    case TelephonyManager.NETWORK_TYPE_UMTS:
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
    case TelephonyManager.NETWORK_TYPE_HSDPA:
    case TelephonyManager.NETWORK_TYPE_HSUPA:
    case TelephonyManager.NETWORK_TYPE_HSPA:
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
    case TelephonyManager.NETWORK_TYPE_EHRPD:
    case TelephonyManager.NETWORK_TYPE_HSPAP:
      return "3G";
    case TelephonyManager.NETWORK_TYPE_LTE:
      return "4G";
    default:
      return "Unknown";
  }
}

代码示例来源:origin: stackoverflow.com

String ts = Context.TELEPHONY_SERVICE;
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(ts);
String imsi = mTelephonyMgr.getSubscriberId();
String imei = mTelephonyMgr.getDeviceId();

代码示例来源:origin: stackoverflow.com

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
String imei = tm.getDeviceId();
String phone = tm.getLine1Number();

代码示例来源:origin: stackoverflow.com

TelephonyManager telemamanger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String getSimSerialNumber = telemamanger.getSimSerialNumber();
String getSimNumber = telemamanger.getLine1Number();

代码示例来源:origin: stackoverflow.com

TelephonyManager tMgr=(TelephonyManager)mcontext.getSystemService(Context.TELEPHONY_SERVICE); 

       Intent intent = new Intent(this, cordovaExample.class);
       PhoneNumber = tMgr.getLine1Number(); // Check PhoneNumber  not null here before send to cordovaExample
if (PhoneNumber !=null ){
        intent.putExtra("novel.PhoneNumber", PhoneNumber);
          startActivity(intent);}

      }

代码示例来源:origin: Blizzard-liu/AndroidUtils

/**
 * 获取设备唯一标识
 * @param context
 * @return
 */
public static String getUUID(Context context) {
  final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  final String tmDevice, tmSerial, tmPhone, androidId;
  tmDevice = "" + tm.getDeviceId();
  tmSerial = "" + tm.getSimSerialNumber();
  androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
  UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
  String uniqueId = deviceUuid.toString();
  if (BuildConfig.DEBUG) Log.d(TAG, "uuid=" + uniqueId);
  return uniqueId;
}

代码示例来源:origin: smuyyh/BookReader

/**
 * 获取手机网络运营商类型
 *
 * @param context
 * @return
 */
public static String getPhoneISP(Context context) {
  if (context == null) {
    return "";
  }
  TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  String teleCompany = "";
  String np = manager.getNetworkOperator();
  if (np != null) {
    if (np.equals(CMCC_ISP) || np.equals(CMCC2_ISP)) {
      teleCompany = "中国移动";
    } else if (np.startsWith(CU_ISP)) {
      teleCompany = "中国联通";
    } else if (np.startsWith(CT_ISP)) {
      teleCompany = "中国电信";
    }
  }
  return teleCompany;
}

代码示例来源:origin: DaxiaK/MyDiary

@Override
public void onClick(View v) {
  switch (v.getId()) {
    case R.id.But_contacts_call_call:
      TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
      if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
        //No module for calling phone
        Toast.makeText(getActivity(), getString(R.string.contacts_call_phone_no_call_function), Toast.LENGTH_LONG)
            .show();
      } else {
        //Can call phone
        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + contactsPhoneNumber));
        startActivity(intent);
      }
      dismiss();
      break;
    case R.id.But_contacts_call_cancel:
      dismiss();
      break;
  }
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

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

代码示例来源:origin: oasisfeng/condom

@Test @SuppressLint("HardwareIds") public void testNullDeviceIdKit() throws NameNotFoundException {
  final CondomContext condom = CondomContext.wrap(new ContextWrapper(context), "NullDeviceId",
      new CondomOptions().addKit(new NullDeviceIdKit()));
  final TelephonyManager tm = (TelephonyManager) condom.getSystemService(Context.TELEPHONY_SERVICE);
  assertNotNull(tm);
  assertTrue(tm.getClass().getName().startsWith(NullDeviceIdKit.class.getName()));
  final TelephonyManager app_tm = (TelephonyManager) condom.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
  assertNotNull(app_tm);
  assertTrue(app_tm.getClass().getName().startsWith(NullDeviceIdKit.class.getName()));
  assertPermission(condom, READ_PHONE_STATE, true);
  assertNull(tm.getDeviceId());
  if (SDK_INT >= LOLLIPOP) {
    if (SDK_INT >= M) assertNull(tm.getDeviceId(0));
    assertNull(tm.getImei());
    assertNull(tm.getImei(0));
    if (SDK_INT >= O) assertNull(tm.getMeid());
    if (SDK_INT >= O) assertNull(tm.getMeid(0));
  }
  assertNull(tm.getSimSerialNumber());
  assertNull(tm.getLine1Number());
  assertNull(tm.getSubscriberId());
}

代码示例来源:origin: jingle1267/android-utils

try {
  WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
  WifiInfo info = wifi.getConnectionInfo();
  String wifiMac = info.getMacAddress();
  TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  String imei = tm.getDeviceId();
  if(!TextUtils.isEmpty(imei)){
    deviceId.append("imei");
  String sn = tm.getSimSerialNumber();
  if(!TextUtils.isEmpty(sn)){
    deviceId.append("sn");

代码示例来源:origin: curtis2/SuperVideoPlayer

@SuppressLint("NewApi")
public static String getIdentifiers(Context ctx) {
 StringBuilder sb = new StringBuilder();
 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO)
   sb.append(getPair("serial", Build.SERIAL));
 else
   sb.append(getPair("serial", "No Serial"));
 sb.append(getPair("android_id", Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID)));
 TelephonyManager tel = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
 sb.append(getPair("sim_country_iso", tel.getSimCountryIso()));
 sb.append(getPair("network_operator_name", tel.getNetworkOperatorName()));
 sb.append(getPair("unique_id", Crypto.md5(sb.toString())));
 ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
 sb.append(getPair("network_type", cm.getActiveNetworkInfo() == null ? "-1" : String.valueOf(cm.getActiveNetworkInfo().getType())));
 return sb.toString();
}

代码示例来源:origin: smuyyh/BookReader

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

代码示例来源:origin: stackoverflow.com

/**
 * Get ISO 3166-1 alpha-2 country code for this device (or null if not available)
 * @param context Context reference to get the TelephonyManager instance from
 * @return country code or null
 */
public static String getUserCountry(Context context) {
  try {
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    final String simCountry = tm.getSimCountryIso();
    if (simCountry != null && simCountry.length() == 2) { // SIM country code is available
      return simCountry.toLowerCase(Locale.US);
    }
    else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) { // device is not 3G (would be unreliable)
      String networkCountry = tm.getNetworkCountryIso();
      if (networkCountry != null && networkCountry.length() == 2) { // network country code is available
        return networkCountry.toLowerCase(Locale.US);
      }
    }
  }
  catch (Exception e) { }
  return null;
}

代码示例来源:origin: ac-pm/Inspeckage

li.add(new FingerprintItem("Wi-Fi", "Android", mac, mac, false));
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
WifiInfo wi = wifiManager.getConnectionInfo();
li.add(new FingerprintItem("Wi-Fi", "IP", ipAddress, ipAddress, false));
TelephonyManager mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
li.add(new FingerprintItem("TelephonyManager", "IMEI", mTelephonyManager.getDeviceId(), mTelephonyManager.getDeviceId(), false));
li.add(new FingerprintItem("TelephonyManager", "IMSI", mTelephonyManager.getSubscriberId(), mTelephonyManager.getSubscriberId(), false));
li.add(new FingerprintItem("TelephonyManager", "PhoneNumber", mTelephonyManager.getLine1Number(), mTelephonyManager.getLine1Number(), false));
li.add(new FingerprintItem("TelephonyManager", "SimSerial", mTelephonyManager.getSimSerialNumber(), mTelephonyManager.getSimSerialNumber(), false));
li.add(new FingerprintItem("TelephonyManager", "CarrierCode", mTelephonyManager.getNetworkOperator(), mTelephonyManager.getNetworkOperator(), false));
li.add(new FingerprintItem("TelephonyManager", "Carrier", mTelephonyManager.getNetworkOperatorName(), mTelephonyManager.getNetworkOperatorName(), false));
li.add(new FingerprintItem("TelephonyManager", "SimCountry", mTelephonyManager.getSimCountryIso(), mTelephonyManager.getSimCountryIso(), false));
li.add(new FingerprintItem("TelephonyManager", "NetworkCountry", mTelephonyManager.getNetworkCountryIso(), mTelephonyManager.getNetworkCountryIso(), false));
li.add(new FingerprintItem("TelephonyManager", "SimSerialNumber", mTelephonyManager.getSimSerialNumber(), mTelephonyManager.getSimSerialNumber(), false));

代码示例来源:origin: rumboalla/apkupdater

private AndroidCheckinProto getCheckinProto() {
  TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  return AndroidCheckinProto.newBuilder()
    .setBuild(getBuildProto())
    .setLastCheckinMsec(0)
    .setCellOperator(tm.getNetworkOperator())
    .setSimOperator(tm.getSimOperator())
    .setRoaming("mobile-notroaming")
    .setUserNumber(0)
    .build()
    ;
}

代码示例来源:origin: stackoverflow.com

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getDeviceId();

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

recordStepInfo("系统版本:\t" + android.os.Build.VERSION.RELEASE);
if (_telManager != null && TextUtils.isEmpty(_deviceID)) {
 _deviceID = _telManager.getDeviceId();
 _ISOCountryCode = _telManager.getNetworkCountryIso();
 String tmp = _telManager.getNetworkOperator();
 if (tmp.length() >= 3) {
  _MobileCountryCode = tmp.substring(0, 3);

相关文章