(TelephonyManager.NETW0RK_TYPE_EVD0_0) case (TelephonyManager.NETW0RK_TYPE_EVD0_A) case (TelephonyManager.NETW0RK_TYPE_EVD0_B) case (TelephonyManager.NETW0RK_TYPE_GPRS) case (TelephonyManager.NETW0RK_TYPE_HSDPA) case (TelephonyManager.NETW0RK_TYPE_HSPA) case (TelephonyManager.NETW0RK_TYPE_HSPAP) case (TelephonyManager.NETW0RK_TYPE_HSUPA) case (TelephonyManager.NETW0RK_TYPE_IDEN) case (TelephonyManager.NETW0RK_TYPE_LTE) case (TelephonyManager.NETW0RK_TYPE_UMTS) case (TelephonyManager.NETW0RK_TYPE_UNKN0WN) default: break;}These commands work only when you are connected to a mobile network and can be unreliable if it is a CDMA network. Use the getPhoneType method, as shown in the preceding code snippet, to determine which phone type is being used. Reading SIM DetailsIf your application is running on a GSM device, it will usually have a SIM. You can query the SIM details from the Telephony Manager to obtain the ISO country code, operator name, and operator MCC and MNC for the SIM installed in the current device. These details can be useful if you need to provide specialized functionality for a particular carrier.If you have included the read_phone_state uses-permission in your application manifest, you can also obtain the serial number for the current SIM using the getSimSerialNumber method when the SIM is in a ready state.Before you can use any of these methods, you must ensure that the SIM is in a ready state. You can determine this using the getSimState method:int simState = telephonyManager.getSimState(); switch (simState) {case (TelephonyManager.SIM_STATE_ABSENT): break; case (TelephonyManager.SIM_STATE_NETW0RK_L0CKED): break; case (TelephonyManager.SIM_STATE_PIN_REQUIRED): break; case (TelephonyManager.SIM_STATE_PUK_REQUIRED): break; case (TelephonyManager.SIM_STATE_UNKN0WN): break; case (TelephonyManager.SIM_STATE_READY): {// Get the SIM country ISO codeString simCountry = telephonyManager.getSimCountryIso();// Get the operator code of the active SIM (MCC + MNC)String simOperatorCode = telephonyManager.getSim0perator();// Get the name of the SIM operatorString simOperatorName = telephonyManager.getSim0peratorName();// -- Requires READ_PH0NE_STATE uses-permission -- // Get the SIM's serial numberString simSerial = telephonyManager.getSimSerialNumber(); break;}default: break;}Reading Data Connection and Transfer State DetailsUsing the getDataState and getDataActivity methods, you can find the current data connection state and data transfer activity, respectively:int dataActivity = telephonyManager.getDataActivity(); int dataState = telephonyManager.getDataState();switch (dataActivity) {case TelephonyManager.DATA_ACTIVITY_IN : break; case TelephonyManager.DATA_ACTIVITY_0UT : break; case TelephonyManager.DATA_ACTIVITY_IN0UT : break; case
đang được dịch, vui lòng đợi..
