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

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

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

TelephonyManager.getSubscriberId介绍

暂无

代码示例

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

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

代码示例来源: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

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

代码示例来源:origin: square/assertj-android

public TelephonyManagerAssert hasSubscriberId(String id) {
 isNotNull();
 String actualId = actual.getSubscriberId();
 assertThat(actualId) //
   .overridingErrorMessage("Expected subscriber ID <%s> but was <%s>.", id, actualId) //
   .isEqualTo(id);
 return this;
}

代码示例来源:origin: jiangqqlmj/FastDev4Android

public static String getIpName() {
  String ipName = null;
  try {
    TelephonyManager mTelephonyManager = (TelephonyManager) FDApplication
        .getInstance().getSystemService(Context.TELEPHONY_SERVICE);
    if (mTelephonyManager != null) {
      String IMSI = mTelephonyManager.getSubscriberId();
      if (IMSI != null && !IMSI.equals("") && IMSI.length() >= 5) {
        // IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。
        ipName = IMSI.substring(3, 5);
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
  return ipName;
}

代码示例来源:origin: jiangqqlmj/FastDev4Android

public static String getIpCountry() {
  String ipCountry = "460";
  try {
    TelephonyManager mTelephonyManager = (TelephonyManager) FDApplication
        .getInstance().getSystemService(Context.TELEPHONY_SERVICE);
    if (mTelephonyManager != null) {
      String IMSI = mTelephonyManager.getSubscriberId();
      if (IMSI != null && !IMSI.equals("") && IMSI.length() >= 3) {
        // IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。
        ipCountry = IMSI.substring(0, 3);
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
  return ipCountry;
}

代码示例来源:origin: jokermonn/permissions4m

/**
 * read phone state, {@link android.Manifest.permission#READ_PHONE_STATE}
 * <p>
 * in {@link com.joker.api.support.manufacturer.XIAOMI} or
 * {@link com.joker.api.support.manufacturer.OPPO}          :
 * -> {@link TelephonyManager#getDeviceId()} will be null if deny permission
 * <p>
 * in {@link com.joker.api.support.manufacturer.MEIZU}      :
 * -> {@link TelephonyManager#getSubscriberId()} will be null if deny permission
 *
 * @param activity
 * @return true if success
 * @throws Exception
 */
@SuppressLint("HardwareIds")
private static boolean checkReadPhoneState(Activity activity) throws Exception {
  TelephonyManager service = (TelephonyManager) activity.getSystemService
      (TELEPHONY_SERVICE);
  if (PermissionsPageManager.isMEIZU()) {
    return !TextUtils.isEmpty(service.getSubscriberId());
  } else if (PermissionsPageManager.isXIAOMI() || PermissionsPageManager.isOPPO()) {
    return !TextUtils.isEmpty(service.getDeviceId());
  } else {
    return !TextUtils.isEmpty(service.getDeviceId()) || !TextUtils.isEmpty(service
        .getSubscriberId());
  }
}

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

@Test
public void shouldSetSubscriberId() {
 String subscriberId = "123451234512345";
 shadowOf(telephonyManager).setSubscriberId(subscriberId);
 assertThat(telephonyManager.getSubscriberId()).isEqualTo(subscriberId);
}

代码示例来源:origin: tianshaojie/AndroidFine

public static String getIMSI(Context context) {
  try {
    if (context == null) {
      return "";
    }
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return telephonyManager.getSubscriberId();
  } catch (Exception exception1) {
  }
  return "";
}

代码示例来源:origin: GeekGhost/Ghost

/**
 * getIMSI</br> Requires Permission:
 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
 *
 * @param context
 * @return
 */
public static String getIMSI(Context context) {
  TelephonyManager mTelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  String imsi = mTelephonyMgr.getSubscriberId();
  if (TextUtils.isEmpty(imsi)) {
    return "0";
  } else {
    return imsi;
  }
}

代码示例来源: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: stackoverflow.com

TelephonyManager tMgr = (TelephonyManager) 
         ShowMyLocation.this.getSystemService(Context.TELEPHONY_SERVICE);

String MyPhoneNumber = "0000000000";

try 
{
  MyPhoneNumber =tMgr.getLine1Number();
}
catch(NullPointerException ex)
{
}

if(MyPhoneNumber.equals("")){
  MyPhoneNumber = tMgr.getSubscriberId();
}

代码示例来源:origin: kingthy/TVRemoteIME

public static NetWorkCarrier getNetWorkCarrier(Context context) {
    if (context != null) {
      TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
      if (telephonyManager != null) {
        try {
          String subscriberId = telephonyManager.getSubscriberId();
          if(subscriberId != null) {
            if (subscriberId.startsWith("46000") || subscriberId.startsWith("46002")) {
              return NetWorkCarrier.CMCC;
            }
            if (subscriberId.startsWith("46001")) {
              return NetWorkCarrier.CU;
            }
            if (subscriberId.startsWith("46003")) {
              return NetWorkCarrier.CT;
            }
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    return NetWorkCarrier.UNKNOWN;
  }
}

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

TelephonyManager tm = (TelephonyManager) mContext
    .getSystemService(Context.TELEPHONY_SERVICE);
imsi_1 = tm.getSubscriberId();
imei_1 = tm.getDeviceId();
TelephonyManager tm1 = (TelephonyManager) mContext
    .getSystemService(spreadTmService);
imsi_2 = tm1.getSubscriberId();
imei_2 = tm1.getDeviceId();
imsInfo = new IMSInfo();

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

TelephonyManager tm2 = (TelephonyManager) mx.invoke(tm, simId_2);
imsi_1 = tm1.getSubscriberId();
imsi_2 = tm2.getSubscriberId();

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

/**
 * 系统的api
 *
 * @return
 */
public IMSInfo getIMSI() {
  IMSInfo imsInfo = null;
  try {
    TelephonyManager tm = (TelephonyManager) mContext
        .getSystemService(Context.TELEPHONY_SERVICE);
    imsi_1 = tm.getSubscriberId();
    imei_1 = tm.getDeviceId();
  } catch (Exception e) {
    // TODO: handle exception
    imsInfo = null;
    return imsInfo;
  }
  if (TextUtils.isEmpty(imsi_1) || imsi_1.length() < 10) {
    imsInfo = null;
    return imsInfo;
  } else {
    imsInfo = new IMSInfo();
    imsInfo.chipName = "单卡芯片";
    imsInfo.imei_1 = imei_1;
    imsInfo.imei_2 = "没有";
    imsInfo.imsi_1 = imsi_1;
    imsInfo.imsi_2 = "没有";
    return imsInfo;
  }
}

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

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));

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

private static String getActiveSubscriberId(Context context) {
  final TelephonyManager tele = TelephonyManager.from(context);
  final String actualSubscriberId = tele.getSubscriberId();
  return SystemProperties.get(TEST_SUBSCRIBER_PROP, actualSubscriberId);
}

代码示例来源: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: stackoverflow.com

TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
 String imsi = mTelephonyMgr.getSubscriberId();
 String imei = mTelephonyMgr.getDeviceId(); 
 String simno = mTelephonyMgr.getSimSerialNumber();
 Log.v("", ""+imsi);
 Log.v("", ""+imei);
 Log.v("", ""+simno);

相关文章