List of usage examples for android.content Context TELEPHONY_SERVICE
String TELEPHONY_SERVICE
To view the source code for android.content Context TELEPHONY_SERVICE.
Click Source Link
From source file:Main.java
public static @Nullable String getSimCountryIso(Context context) { String simCountryIso = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)) .getSimCountryIso();/* w w w . j a va 2 s . c o m*/ return simCountryIso != null ? simCountryIso.toUpperCase() : null; }
From source file:Main.java
private static String getDeviceId(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String tmDevice = null;//w w w . j a va2s .c o m String tmSerial = null; String androidId = null; try { tmDevice = tm.getDeviceId(); } catch (Exception e) { Log.w(LOG_TAG, e); } try { tmSerial = tm.getSimSerialNumber(); } catch (Exception e) { Log.w(LOG_TAG, e); } androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); if (tmDevice == null) { tmDevice = ""; } if (tmSerial == null) { tmSerial = ""; } if (androidId == null) { androidId = ""; } UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); return "lsa-kp" + deviceUuid.toString(); }
From source file:Main.java
protected static Object getITelephony(final Context context) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException, IllegalAccessException { final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); final Method getITelephony = tm.getClass().getDeclaredMethod("getITelephony"); if (!getITelephony.isAccessible()) { getITelephony.setAccessible(true); }//from w w w. j a v a2 s. c om return getITelephony.invoke(tm); }
From source file:Main.java
/** * Returns whether the device is voice-capable (meaning, it can do MMS). *//*w ww.ja v a 2 s .c o m*/ public static boolean isMmsCapable(Context context) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager == null) { return false; } try { Class partypes[] = new Class[0]; Method sIsVoiceCapable = TelephonyManager.class.getMethod("isVoiceCapable", partypes); Object arglist[] = new Object[0]; Object retobj = sIsVoiceCapable.invoke(telephonyManager, arglist); return (Boolean) retobj; } catch (java.lang.reflect.InvocationTargetException ite) { // Failure, must be another device. // Assume that it is voice capable. } catch (IllegalAccessException iae) { // Failure, must be an other device. // Assume that it is voice capable. } catch (NoSuchMethodException nsme) { } return true; }
From source file:Main.java
/** * Returns the IMEI Number./*w ww .j a va 2s . c om*/ * @return - Device IMEI number. */ public static String getDeviceId(Context context) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String deviceId = telephonyManager.getDeviceId(); if (deviceId == null || deviceId.isEmpty()) { deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); } return deviceId; }
From source file:Main.java
private static String getPhoneIMEI(Context context) { String result = null;//from w w w.java2 s. co m try { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); result = tm.getDeviceId(); } catch (Exception e) { Log.w(LOG_TAG, e); } return result == null ? "" : result; }
From source file:Main.java
public static String getImsi(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return tm.getSubscriberId(); }
From source file:Main.java
public static String getNetClass(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:/*from w ww .ja v a2s. c o m*/ return "Unknown"; } }
From source file:Main.java
public static String getOwnNumber(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return tm.getLine1Number(); }
From source file:Main.java
public static boolean is2gNetwork(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); int type = tm.getNetworkType(); if (type == TelephonyManager.NETWORK_TYPE_GPRS || type == TelephonyManager.NETWORK_TYPE_EDGE) { return true; }//from w w w . j a v a 2 s. c o m return false; }