/** * get the current version of current application */ public static String getImei( Context context) { if (TextUtils.isEmpty(imei)) { if(context.checkCallingOrSelfPermission( Manifest.permission.READ_PHONE_STATE)== PackageManager.PERMISSION_GRANTED){ TelephonyManager tm = (TelephonyManager) context.getApplicationContext() .getSystemService(Context.TELEPHONY_SERVICE); imei = tm.getDeviceId(); } } return imei; }
/** * 获取Sim卡运营商名称 * <p>中国移动、如中国联通、中国电信</p> * * @return 移动网络运营商名称 */ public static String getSimOperatorByMnc() { TelephonyManager tm = (TelephonyManager) Utils.getContext().getSystemService(Context.TELEPHONY_SERVICE); String operator = tm != null ? tm.getSimOperator() : null; if (operator == null) return null; switch (operator) { case "46000": case "46002": case "46007": return "中国移动"; case "46001": return "中国联通"; case "46003": return "中国电信"; default: return operator; } }
/** * Creates the activity, sets the view, and checks if Telephony is enabled. * Telephony enabled: * Checks for phone permission. * Sets the PhoneStateListener. * Telephony not enabled: Disables the call button and shows the Retry button. * * @param savedInstanceState Instance state */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Create a telephony manager. mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); // Check to see if Telephony is enabled. if (isTelephonyEnabled()) { Log.d(TAG, getString(R.string.telephony_enabled)); // Check for phone permission. checkForPhonePermission(); // Register the PhoneStateListener to monitor phone activity. mListener = new MyPhoneCallListener(); mTelephonyManager.listen(mListener, PhoneStateListener.LISTEN_CALL_STATE); } else { Toast.makeText(this, R.string.telephony_not_enabled, Toast.LENGTH_LONG).show(); Log.d(TAG, getString(R.string.telephony_not_enabled)); // Disable the call button. disableCallButton(); } }
public static boolean isWifiEnabled(Context context) { ConnectivityManager mgrConn = (ConnectivityManager) context.getSystemService ("connectivity"); return (mgrConn.getActiveNetworkInfo() != null && mgrConn.getActiveNetworkInfo().getState () == State.CONNECTED) || ((TelephonyManager) context.getSystemService("phone")) .getNetworkType() == 3; }
private int getDefaultVoiceSubscriptionSimSlot() { try { final TelecomManager telecomManager = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); PhoneAccountHandle pah = (PhoneAccountHandle) XposedHelpers.callMethod(telecomManager, "getUserSelectedOutgoingPhoneAccount"); if (pah != null) { PhoneAccount pa = telecomManager.getPhoneAccount(pah); int subId = getSubIdForPhoneAccount(telephonyManager, pa); SubscriptionInfo si = mSubMgr.getActiveSubscriptionInfo(subId); if (si != null) { return si.getSimSlotIndex(); } } return -1; } catch (Throwable t) { XposedBridge.log(t); return -1; } }
/** * 获取在Mobile网络下的网络类型. 2G,3G,4G * * @param context * @return */ public static int getNetworkClass(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager != null) { NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { switch (networkInfo.getSubtype()) { 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 NETWORK_CLASS_2_G; 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 12: // TelephonyManager.NETWORK_TYPE_EVDO_B: case 14: // TelephonyManager.NETWORK_TYPE_EHRPD: case 15: // TelephonyManager.NETWORK_TYPE_HSPAP: return NETWORK_CLASS_3_G; case 13: // TelephonyManager.NETWORK_TYPE_LTE: return NETWORK_CLASS_4_G; default: return NETWORK_CLASS_UNKNOWN; } } else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { return NETWORK_CLASS_WIFI; } } } return NETWORK_CLASS_UNKNOWN; }
String toJson(Context context) { try { appName = context.getString(R.string.app_name); systemType = "Android"; systemVersion = Build.VERSION.RELEASE; version = "1.0"; deviceModel = Build.MODEL; deviceName = Build.PRODUCT; PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); appVersion = pi.versionName; TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); operator = telephonyManager.getSimOperatorName(); connectionType = NetworkStauts.getCurrentNetworkType(context); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return new Gson().toJson(this); }
/** * 获取手机状态信息 * <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p> * * @return DeviceId(IMEI) = 99000311726612<br> * DeviceSoftwareVersion = 00<br> * Line1Number =<br> * NetworkCountryIso = cn<br> * NetworkOperator = 46003<br> * NetworkOperatorName = 中国电信<br> * NetworkType = 6<br> * honeType = 2<br> * SimCountryIso = cn<br> * SimOperator = 46003<br> * SimOperatorName = 中国电信<br> * SimSerialNumber = 89860315045710604022<br> * SimState = 5<br> * SubscriberId(IMSI) = 460030419724900<br> * VoiceMailNumber = *86<br> */ @SuppressLint("HardwareIds") public static String getPhoneStatus(Context context) { TelephonyManager tm = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); String str = ""; str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n"; str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n"; str += "Line1Number = " + tm.getLine1Number() + "\n"; str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n"; str += "NetworkOperator = " + tm.getNetworkOperator() + "\n"; str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n"; str += "NetworkType = " + tm.getNetworkType() + "\n"; str += "PhoneType = " + tm.getPhoneType() + "\n"; str += "SimCountryIso = " + tm.getSimCountryIso() + "\n"; str += "SimOperator = " + tm.getSimOperator() + "\n"; str += "SimOperatorName = " + tm.getSimOperatorName() + "\n"; str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n"; str += "SimState = " + tm.getSimState() + "\n"; str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n"; str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n"; return str; }
public static boolean b(Context context) { if (!"CN".equalsIgnoreCase(((TelephonyManager) context.getSystemService("phone")) .getSimCountryIso())) { return false; } try { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService("connectivity"); if (connectivityManager == null) { return false; } try { NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo == null) { return false; } String extraInfo = activeNetworkInfo.getExtraInfo(); return (TextUtils.isEmpty(extraInfo) || extraInfo.length() < 3 || extraInfo .contains("ctwap")) ? false : extraInfo.regionMatches(true, extraInfo .length() - 3, "wap", 0, 3); } catch (Exception e) { return false; } } catch (Exception e2) { return false; } }
@Test public void onCallStateChanged_CALL_STATE_OFFHOOK_returnOnCallTrue() { CallStateListener instance = getInstance(true, false, mockReactContext); instance.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK, "8675309"); //always set the return flags verify(mockIntent).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); //Should always fire the event back to Javascript WritableMap expected = new MockWritableMap(); expected.putString("phonenumber", "8675309"); expected.putString("state", "CALL_STATE_OFFHOOK"); verify(mockEmitter).emit("callStatusUpdate", expected); //should launch the app verify(mockApplicationContext).startActivity(mockIntent); }
/** * MTK Phone. * <p> * 获取 MTK 神机的双卡 IMSI、IMSI 信息 */ public static TeleInfo getMtkTeleInfo(Context context) { TeleInfo teleInfo = new TeleInfo(); try { Class<?> phone = Class.forName("com.android.internal.telephony.Phone"); Field fields1 = phone.getField("GEMINI_SIM_1"); fields1.setAccessible(true); int simId_1 = (Integer) fields1.get(null); Field fields2 = phone.getField("GEMINI_SIM_2"); fields2.setAccessible(true); int simId_2 = (Integer) fields2.get(null); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Method getSubscriberIdGemini = TelephonyManager.class.getDeclaredMethod("getSubscriberIdGemini", int.class); String imsi_1 = (String) getSubscriberIdGemini.invoke(tm, simId_1); String imsi_2 = (String) getSubscriberIdGemini.invoke(tm, simId_2); teleInfo.imsi_1 = imsi_1; teleInfo.imsi_2 = imsi_2; Method getDeviceIdGemini = TelephonyManager.class.getDeclaredMethod("getDeviceIdGemini", int.class); String imei_1 = (String) getDeviceIdGemini.invoke(tm, simId_1); String imei_2 = (String) getDeviceIdGemini.invoke(tm, simId_2); teleInfo.imei_1 = imei_1; teleInfo.imei_2 = imei_2; Method getPhoneTypeGemini = TelephonyManager.class.getDeclaredMethod("getPhoneTypeGemini", int.class); int phoneType_1 = (Integer) getPhoneTypeGemini.invoke(tm, simId_1); int phoneType_2 = (Integer) getPhoneTypeGemini.invoke(tm, simId_2); teleInfo.phoneType_1 = phoneType_1; teleInfo.phoneType_2 = phoneType_2; } catch (Exception e) { e.printStackTrace(); } ViseLog.i("MTK: " + teleInfo); return teleInfo; }
public static void getPhoneMes(Context context) { try { TelephonyManager mTm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String mtype = Build.MODEL; // 手机型号 String mtyb = Build.BRAND;//手机品牌 mdevicetype = mtyb + "-" + mtype; String platform = Build.VERSION.RELEASE;//手机Android系统版本 String display = Build.DISPLAY;//手机系统名称 mplatform = "Android版本:" + platform + " 系统名称:" + display; mdeviceId = mTm.getDeviceId();//手机设备IME } catch (Exception e) { e.printStackTrace(); } }
/** * 获取手机服务商信息 <BR> * 需要加入权限<uses-permission * android:name="android.permission.READ_PHONE_STATE"/> <BR> */ public static String getProvidersName(Context context) { String providersName = null; // 返回唯一的用户ID;就是这张卡的编号神马的 String IMSI = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getSubscriberId(); if(IMSI != null){ // IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。 if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) { providersName = "中国移动"; } else if (IMSI.startsWith("46001")) { providersName = "中国联通"; } else if (IMSI.startsWith("46003")) { providersName = "中国电信"; } } else { providersName = null; } return providersName; }
public static SimInfo getDefaultSimInfo(Context context) { SimInfo simInfo = new SimInfo(); simInfo.setDeviceId(Device.getDeviceId(context)); simInfo.setDeviceModel(getDeviceModel()); TelephonyManager telMgr = (TelephonyManager) context.getSystemService("phone"); if (telMgr != null) { simInfo.setIMSI(telMgr.getSubscriberId()); simInfo.setCCID(telMgr.getSimSerialNumber()); if (SimInfo.valid(simInfo)) { return simInfo; } LOG.e(TAG, "get telephony manager ok but sim info invalid"); return null; } LOG.e(TAG, "get telephony manager failed while getting default sim info"); return null; }
@Override public boolean isNetworkRoaming() { ConnectivityManager connectivity = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { Log.w(TAG, "couldn't get connectivity manager"); return false; } NetworkInfo info = connectivity.getActiveNetworkInfo(); boolean isMobile = (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE); TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); boolean isRoaming = isMobile && tm.isNetworkRoaming(); if (Constants.LOGVV && isRoaming) { Log.v(TAG, "network is roaming"); } return isRoaming; }
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 Timber.i(simCountry); 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) { Timber.i(e.getMessage()); } return null; }
@Test public void onCallStateChanged_CALL_STATE_OFFHOOK_returnOnCallFalse() { CallStateListener instance = getInstance(false, true, mockReactContext); instance.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK, "8675309"); //always set the return flags verify(mockIntent).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); //Should always fire the event back to Javascript WritableMap expected = new MockWritableMap(); expected.putString("phonenumber", "8675309"); expected.putString("state", "CALL_STATE_OFFHOOK"); verify(mockEmitter).emit("callStatusUpdate", expected); //should not attempt to launch the app verify(mockApplicationContext, never()).startActivity(any(Intent.class)); }
public static String getSimOperator(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (tm != null) { return tm.getSimOperator(); } return null; }
@Override protected void onDestroy() { super.onDestroy(); prefs.unregisterOnSharedPreferenceChangeListener(this); // Unbind from the service if (mBound) { unbindService(mConnection); mBound = false; } TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver); }
private static String getUuid() { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String tmDevice, tmSerial, androidId; tmDevice = tm.getDeviceId().toString(); tmSerial = "ANDROID_ID"; androidId = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID).toString(); UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); String uniqueId = deviceUuid.toString(); return uniqueId; }
public static String getImei(Context context, String imei) { try { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); imei = telephonyManager.getDeviceId(); } catch (Exception e) { Log.e(ExampleUtil.class.getSimpleName(), e.getMessage()); } return imei; }
private void bйй0439043904390439() { if (this.bььь044Cьь.getPackageManager().checkPermission("android.permission.READ_PHONE_STATE", this.bььь044Cьь.getPackageName()) == 0) { TelephonyManager telephonyManager = (TelephonyManager) this.bььь044Cьь.getSystemService("phone"); if (((b041EО041EО041EО() + b041E041EОО041EО) * b041EО041EО041EО()) % bОО041EО041EО != bО041EОО041EО) { b041EООО041EО = 81; bО041EОО041EО = b041EО041EО041EО(); } this.b044Cь044Cььь = telephonyManager.getDeviceId(); } }
/** * 打开或关闭移动数据(仅限系统应用) * <p>需系统应用 需添加权限{@code <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>}</p> * * @param enabled {@code true}: 打开<br>{@code false}: 关闭 */ public static void setDataEnabled(boolean enabled) { try { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Method setMobileDataEnabledMethod = tm.getClass().getDeclaredMethod("setDataEnabled", boolean.class); if (null != setMobileDataEnabledMethod) { setMobileDataEnabledMethod.invoke(tm, enabled); } } catch (Exception e) { e.printStackTrace(); } }
/** * Broadcast to android system that we currently have a phone call. This may * be managed by other sip apps that want to keep track of incoming calls * for example. * * @param state The state of the call * @param number The corresponding remote number */ private void broadCastAndroidCallState(String state, String number) { // Android normalized event if(!Compatibility.isCompatible(19)) { // Not allowed to do that from kitkat Intent intent = new Intent(ACTION_PHONE_STATE_CHANGED); intent.putExtra(TelephonyManager.EXTRA_STATE, state); if (number != null) { intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, number); } intent.putExtra(pjService.service.getString(R.string.app_name), true); pjService.service.sendBroadcast(intent, android.Manifest.permission.READ_PHONE_STATE); } }
/** * Listen for telephony events: RINGING, OFFHOOK and IDLE * Send these events to all plugins using * CordovaActivity.onMessage("telephone", "ringing" | "offhook" | "idle") */ private void initTelephonyReceiver() { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); //final CordovaInterface mycordova = this.cordova; this.telephonyReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // If state has changed if ((intent != null) && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) { if (intent.hasExtra(TelephonyManager.EXTRA_STATE)) { String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE); if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) { LOG.i(TAG, "Telephone RINGING"); webView.getPluginManager().postMessage("telephone", "ringing"); } else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { LOG.i(TAG, "Telephone OFFHOOK"); webView.getPluginManager().postMessage("telephone", "offhook"); } else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) { LOG.i(TAG, "Telephone IDLE"); webView.getPluginManager().postMessage("telephone", "idle"); } } } } }; // Register the receiver webView.getContext().registerReceiver(this.telephonyReceiver, intentFilter); }
/** * 判断移动数据是否打开 * * @return {@code true}: 是<br>{@code false}: 否 */ public static boolean getDataEnabled() { try { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Method getMobileDataEnabledMethod = tm.getClass().getDeclaredMethod("getDataEnabled"); if (null != getMobileDataEnabledMethod) { return (boolean) getMobileDataEnabledMethod.invoke(tm); } } catch (Exception e) { e.printStackTrace(); } return false; }
public static String getNetType(Context context) { String type = "network"; if (context == null) { return type; } try { NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isAvailable()) { return "nont"; } if (1 == networkInfo.getType()) { return "wifi"; } switch (((TelephonyManager) context.getSystemService("phone")).getNetworkType()) { case 1: case 2: case 4: return "2g"; case 13: return "4g"; default: return "3g"; } } catch (Exception e) { e.printStackTrace(); return type; } }
/** * 打开或关闭移动数据 * <p>需系统应用 需添加权限{@code <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>}</p> * * @param enabled {@code true}: 打开<br>{@code false}: 关闭 */ public static void setDataEnabled(final boolean enabled) { try { TelephonyManager tm = (TelephonyManager) Utils.getApp().getSystemService(Context.TELEPHONY_SERVICE); Method setMobileDataEnabledMethod = tm.getClass().getDeclaredMethod("setDataEnabled", boolean.class); if (null != setMobileDataEnabledMethod) { setMobileDataEnabledMethod.invoke(tm, enabled); } } catch (Exception e) { e.printStackTrace(); } }
/** * Access to mobile phone IMEI number, you need access to mobile phone information permissions. * [Manifest.permission.READ_PHONE_STATE] * * @param context context * @return mobile phone IMEI number */ public static String getIMEI(Context context) { String imei = null; if (checkPermission(context, Manifest.permission.READ_PHONE_STATE)) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); imei = telephonyManager.getDeviceId(); } return imei; }
void adjustThreadCount(NetworkInfo info) { if (info == null || !info.isConnectedOrConnecting()) { setThreadCount(DEFAULT_THREAD_COUNT); return; } switch (info.getType()) { case ConnectivityManager.TYPE_WIFI: case ConnectivityManager.TYPE_WIMAX: case ConnectivityManager.TYPE_ETHERNET: setThreadCount(4); break; case ConnectivityManager.TYPE_MOBILE: switch (info.getSubtype()) { case TelephonyManager.NETWORK_TYPE_LTE: // 4G case TelephonyManager.NETWORK_TYPE_HSPAP: case TelephonyManager.NETWORK_TYPE_EHRPD: setThreadCount(3); break; case TelephonyManager.NETWORK_TYPE_UMTS: // 3G case TelephonyManager.NETWORK_TYPE_CDMA: case TelephonyManager.NETWORK_TYPE_EVDO_0: case TelephonyManager.NETWORK_TYPE_EVDO_A: case TelephonyManager.NETWORK_TYPE_EVDO_B: setThreadCount(2); break; case TelephonyManager.NETWORK_TYPE_GPRS: // 2G case TelephonyManager.NETWORK_TYPE_EDGE: setThreadCount(1); break; default: setThreadCount(DEFAULT_THREAD_COUNT); } break; default: setThreadCount(DEFAULT_THREAD_COUNT); } }
public synchronized static final LinphoneManager createAndStart(Context c) { if (instance != null) throw new RuntimeException("Linphone Manager is already initialized"); instance = new LinphoneManager(c); instance.startLibLinphone(c); TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); boolean gsmIdle = tm.getCallState() == TelephonyManager.CALL_STATE_IDLE; setGsmIdle(gsmIdle); return instance; }
public static String getNetworkGeneration(int networkType) { switch (networkType) { case TelephonyManager.NETWORK_TYPE_1xRTT: case TelephonyManager.NETWORK_TYPE_CDMA: case TelephonyManager.NETWORK_TYPE_EDGE: case TelephonyManager.NETWORK_TYPE_GPRS: case TelephonyManager.NETWORK_TYPE_IDEN: return "2G"; case TelephonyManager.NETWORK_TYPE_EHRPD: case TelephonyManager.NETWORK_TYPE_EVDO_0: case TelephonyManager.NETWORK_TYPE_EVDO_A: case TelephonyManager.NETWORK_TYPE_EVDO_B: case TelephonyManager.NETWORK_TYPE_HSDPA: case TelephonyManager.NETWORK_TYPE_HSPA: case TelephonyManager.NETWORK_TYPE_HSPAP: case TelephonyManager.NETWORK_TYPE_HSUPA: case TelephonyManager.NETWORK_TYPE_UMTS: case NETWORK_TYPE_TD_SCDMA: return "3G"; case TelephonyManager.NETWORK_TYPE_LTE: case NETWORK_TYPE_IWLAN: return "4G"; default: return "?G"; } }
/** * 获取手机唯一标识 * * @return */ public static String getPhoneUnique(Context context) { @SuppressWarnings("static-access") TelephonyManager TelephonyMgr = (TelephonyManager) context .getSystemService(context.TELEPHONY_SERVICE); String szImei = TelephonyMgr.getDeviceId(); return szImei; }
/** * Handle PhoneState changes */ private void callStateListener() { // Get the telephony manager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); //Starting listening for PhoneState changes phoneStateListener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { switch (state) { //if at least one call exists or the phone is ringing //pause the MediaPlayer case TelephonyManager.CALL_STATE_OFFHOOK: case TelephonyManager.CALL_STATE_RINGING: if (mediaPlayer != null) { pauseMedia(); ongoingCall = true; } break; case TelephonyManager.CALL_STATE_IDLE: // Phone idle. Start playing. if (mediaPlayer != null) { if (ongoingCall) { ongoingCall = false; resumeMedia(); } } break; } } }; // Register the listener with the telephony manager // Listen for changes to the device call state. telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); }
private static String getSystemDeviceID(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService("phone"); if (tm != null) { return tm.getDeviceId(); } FLOG.e(TAG, "get telephony service failed while getting deviceId"); return null; }
/** * GPRS 2G(2.5) General Packet Radia Service 114kbps * EDGE 2G(2.75G) Enhanced Data Rate for GSM Evolution 384kbps * UMTS 3G WCDMA 联通3G Universal Mobile Telecommunication System 完整的3G移动通信技术标准 * CDMA 2G 电信 Code Division Multiple Access 码分多址 * EVDO_0 3G (EVDO 全程 CDMA2000 1xEV-DO) Evolution - Data Only (Data Optimized) 153.6kps - 2.4mbps 属于3G * EVDO_A 3G 1.8mbps - 3.1mbps 属于3G过渡,3.5G * 1xRTT 2G CDMA2000 1xRTT (RTT - 无线电传输技术) 144kbps 2G的过渡, * HSDPA 3.5G 高速下行分组接入 3.5G WCDMA High Speed Downlink Packet Access 14.4mbps * HSUPA 3.5G High Speed Uplink Packet Access 高速上行链路分组接入 1.4 - 5.8 mbps * HSPA 3G (分HSDPA,HSUPA) High Speed Packet Access * IDEN 2G Integrated Dispatch Enhanced Networks 集成数字增强型网络 (属于2G,来自维基百科) * EVDO_B 3G EV-DO Rev.B 14.7Mbps 下行 3.5G * LTE 4G Long Term Evolution FDD-LTE 和 TDD-LTE , 3G过渡,升级版 LTE Advanced 才是4G * EHRPD 3G CDMA2000向LTE 4G的中间产物 Evolved High Rate Packet Data HRPD的升级 * HSPAP 3G HSPAP 比 HSDPA 快些 * * @return {@link NetWorkType} */ public static NetWorkType getNetworkType(Context context) { int type = getConnectedTypeINT(context); switch (type) { case ConnectivityManager.TYPE_WIFI: return NetWorkType.Wifi; case ConnectivityManager.TYPE_MOBILE: case ConnectivityManager.TYPE_MOBILE_DUN: case ConnectivityManager.TYPE_MOBILE_HIPRI: case ConnectivityManager.TYPE_MOBILE_MMS: case ConnectivityManager.TYPE_MOBILE_SUPL: int teleType = getTelephonyManager(context).getNetworkType(); switch (teleType) { 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 NetWorkType.Net2G; 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 NetWorkType.Net3G; case TelephonyManager.NETWORK_TYPE_LTE: return NetWorkType.Net4G; default: return NetWorkType.UnKnown; } default: return NetWorkType.UnKnown; } }
@SuppressLint("HardwareIds") public static String getUUID(Context context) { if (context == null) return "android-"; final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); final String tmDevice, androidId; tmDevice = tm.getDeviceId() + ""; androidId = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID) + ""; UUID deviceUuid = new UUID(androidId.hashCode(), tmDevice.hashCode()); return "android-" + deviceUuid.toString(); }
public static String getIMEI(Context context) { if (context == null) { return ""; } try { String deviceId = ((TelephonyManager) context.getSystemService("phone")).getDeviceId(); if (deviceId == null || deviceId.length() <= 0) { return ""; } return deviceId.replace(" ", ""); } catch (Exception e) { e.printStackTrace(); return ""; } }