android.telephony.TelephonyManager.getImei()方法的使用及代码示例

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

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

TelephonyManager.getImei介绍

暂无

代码示例

代码示例来源:origin: robolectric/robolectric

@Test
@Config(minSdk = O)
public void getImei() {
 String testImei = "4test imei";
 shadowOf(telephonyManager).setImei(testImei);
 assertEquals(testImei, telephonyManager.getImei());
}

代码示例来源:origin: robolectric/robolectric

@Test
@Config(minSdk = O)
public void getImeiForSlot() {
 shadowOf(telephonyManager).setImei("defaultImei");
 shadowOf(telephonyManager).setImei(0, "imei0");
 shadowOf(telephonyManager).setImei(1, "imei1");
 assertEquals("imei0", telephonyManager.getImei(0));
 assertEquals("imei1", telephonyManager.getImei(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: Trumeet/MiPushFramework

@Test @SuppressLint("HardwareIds") public void testNullDeviceIdKit() {
  final CondomContext condom = CondomContext.wrap(new ContextWrapper(context), "NullDeviceId",
      new CondomOptions().addKit(new NullDeviceIdKit()));
  final TelephonyManager tm = (TelephonyManager) condom.getSystemService(Context.TELEPHONY_SERVICE);
  assertTrue(condom.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE).getClass().getName().startsWith(NullDeviceIdKit.class.getName()));
  assertPermission(condom, READ_PHONE_STATE, true);
  assertNull(tm.getDeviceId());
  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: adjust/android_sdk

private static String getImeiByIndex(TelephonyManager telephonyManager, int index, ILogger logger) {
  try {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      return telephonyManager.getImei(index);
    }
  } catch (SecurityException e) {
    logger.debug("Couldn't read IMEI in position %d: %s", index, e.getMessage());
  }
  return null;
}

代码示例来源:origin: adjust/android_sdk

private static String getDefaultImei(TelephonyManager telephonyManager, ILogger logger) {
  try {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      return telephonyManager.getImei();
    }
  } catch (SecurityException e) {
    logger.debug("Couldn't read default IMEI: %s", e.getMessage());
  }
  return null;
}

代码示例来源:origin: linqssonny/Utils

/**
 * return Imei(International Mobile Equipment Identity), may be return null.
 *
 * @param context
 * @return
 */
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public static String getImei(Context context) {
  TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  if (null == telephonyManager) {
    return null;
  }
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    return telephonyManager.getImei();
  } else {
    return telephonyManager.getDeviceId();
  }
}

相关文章