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 boolean checkGprsNetwork(Context context) { boolean has = false; ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); NetworkInfo info = connectivity.getActiveNetworkInfo(); int netType = info.getType(); int netSubtype = info.getSubtype(); if (netType == ConnectivityManager.TYPE_MOBILE && netSubtype == TelephonyManager.NETWORK_TYPE_UMTS && !mTelephony.isNetworkRoaming()) { has = info.isConnected();/* w w w. ja va2s . c om*/ } return has; }
From source file:Main.java
/** * This Function return the Android DeviceID in String format. Always to add * following Permission in Manifest.// w w w. ja va2 s . com * * Requires Permission: READ_PHONE_STATE * * See below for @params. */ public static String getDeviceID(Context ctx) { TelephonyManager telephonyManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); String iemi = telephonyManager.getDeviceId(); return iemi; }
From source file:Main.java
/** * get app imei/*www .ja va 2s . c om*/ * @param context * @return */ @TargetApi(Build.VERSION_CODES.CUPCAKE) public static String getDeviceIMEI(Context context) { String deviceId; if (isPhone(context)) { TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); deviceId = telephony.getDeviceId(); } else { deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); } return deviceId; }
From source file:Main.java
public static int getPhoneType(Context context) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return telephonyManager.getPhoneType(); }
From source file:Main.java
/** * Returns the ISO code of the current country * @param context Context in which the application is running * @return the ISO code of the current country, or null if not found *///w w w . j a v a 2s.c o m @Nullable public static String getCountryIso(Context context) { if (context != null) { TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null) return telephonyManager.getNetworkCountryIso().toLowerCase(); } return null; }
From source file:Main.java
/** * Get ISO 3166-1 alpha-2 country code for this device (or null if not available) * * @param context Context reference to get the TelephonyManager instance from * @return country code or null/* ww w. java 2 s .c o m*/ */ public static String getDeviceCountry(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 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) { } return null; }
From source file:Main.java
public static boolean supportSMS(Context ctx) { //Froyo or above!! TelephonyManager telephonyManager1 = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); boolean isPhone = !(telephonyManager1.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE); boolean featureTelephony = ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY); return isPhone && featureTelephony; }
From source file:Main.java
/** * Whether is fast mobile network/* w w w.ja va 2 s . c om*/ * * @param context * @return */ private static boolean isFastMobileNetwork(Context context) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager == null) { return false; } switch (telephonyManager.getNetworkType()) { case TelephonyManager.NETWORK_TYPE_EVDO_0: case TelephonyManager.NETWORK_TYPE_EVDO_A: case TelephonyManager.NETWORK_TYPE_HSDPA: case TelephonyManager.NETWORK_TYPE_HSPA: case TelephonyManager.NETWORK_TYPE_HSUPA: case TelephonyManager.NETWORK_TYPE_UMTS: case TelephonyManager.NETWORK_TYPE_EHRPD: case TelephonyManager.NETWORK_TYPE_EVDO_B: case TelephonyManager.NETWORK_TYPE_HSPAP: case TelephonyManager.NETWORK_TYPE_LTE: return true; case TelephonyManager.NETWORK_TYPE_IDEN: case TelephonyManager.NETWORK_TYPE_UNKNOWN: case TelephonyManager.NETWORK_TYPE_1xRTT: case TelephonyManager.NETWORK_TYPE_CDMA: case TelephonyManager.NETWORK_TYPE_EDGE: case TelephonyManager.NETWORK_TYPE_GPRS: default: return false; } }
From source file:Main.java
public static String getIMSI(Context context) { String imsi = ""; try {//from w w w . j a va 2s . com TelephonyManager phoneManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); imsi = phoneManager.getSubscriberId(); Log.v(TAG, imsi); } catch (Exception e) { Log.e(TAG, "getIMSI error!"); imsi = ""; } if (imsi == null) { imsi = ""; } return imsi; }
From source file:Main.java
private static TelephonyManager getTelephonyManager(Context con) { if (telephonyManager == null) { telephonyManager = (TelephonyManager) con.getSystemService(Context.TELEPHONY_SERVICE); return telephonyManager; } else {//w w w . j ava2 s .c om return telephonyManager; } }