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
/** * @param context/* ww w .j a va 2 s.c o m*/ * @return device token/id */ public static String getDeviceID(Context context) { // TODO Auto-generated method stub TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return telephonyManager.getDeviceId(); }
From source file:Main.java
/** * * @param context// w ww . j a v a2s . c o m * @return bool, true se c'e il modulo telefonico oppure se la sim e attiva */ public static boolean isTelephonyEnabled(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return tm != null && tm.getSimState() == TelephonyManager.SIM_STATE_READY; }
From source file:Main.java
static String getPhoneImei(Context context) { @SuppressLint("HardwareIds") String imei = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); if (TextUtils.isEmpty(imei)) { imei = "na"; }//w w w .j a v a2s . com return imei; }
From source file:Main.java
public static String getDeviceIMEI(Context context) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager == null || TextUtils.isEmpty(telephonyManager.getDeviceId())) { return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); } else {//from w ww . ja v a2s . c om return telephonyManager.getDeviceId(); } }
From source file:Main.java
private static String generateDeviceUniqueIdentifier(Context context) { final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); final String tmDevice = "" + tm.getDeviceId(); final String tmSerial = "" + tm.getSimSerialNumber(); final String androidId = "" + Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); final String packageBasedAndroidId = context.getPackageName() + androidId; UUID deviceUuid = new UUID(packageBasedAndroidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); return deviceUuid.toString(); }
From source file:Main.java
public static String get_device_id(Context ctx) { final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); String tmDevice = ""; String tmSerial = null;//from ww w. j ava 2 s. c o m String androidId = null; try { tmDevice = "" + tm.getDeviceId(); } catch (Exception ex) { } try { tmSerial = "" + tm.getSimSerialNumber(); } catch (Exception ex) { } try { androidId = "" + android.provider.Settings.Secure.getString(ctx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); } catch (Exception ex) { } try { UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); String deviceId = deviceUuid.toString(); MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(deviceId.getBytes()); byte byteData[] = md.digest(); //convert the byte to hex format method 1 StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } deviceId = sb.toString(); return deviceId; } catch (Exception ex) { } return "nodeviceid"; }
From source file:Main.java
public static String getDeviceInfo(Context context) { try {/*from w w w. j a va 2s .co m*/ android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); String device_id = tm.getDeviceId(); if (TextUtils.isEmpty(device_id)) { android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) context .getSystemService(Context.WIFI_SERVICE); device_id = wifi.getConnectionInfo().getMacAddress(); } if (TextUtils.isEmpty(device_id)) { device_id = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); } return device_id; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
/** * Use for getting your device id if available. * * @param context/*from w w w .java 2s . c o m*/ * @return your device id */ public static String getDeviceId(Context context) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return telephonyManager.getDeviceId(); }
From source file:Main.java
public static String getICCID(Context context) { String iccid = ""; try {/* w w w.java 2 s.c om*/ TelephonyManager phoneManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); iccid = phoneManager.getSimSerialNumber(); } catch (Exception e) { Log.e(TAG, "getIMEI error!"); iccid = ""; } if (iccid == null) { iccid = ""; } return iccid; }
From source file:Main.java
public static boolean isRunningOnEmulator(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String networkOperator = tm.getNetworkOperatorName(); Log.v(TAG, "Network operator is " + networkOperator); if (networkOperator.equals("Android")) { Log.i(TAG, "Running on emulator."); return true; }/*from ww w . j a v a 2 s. c o m*/ Log.i(TAG, "Running on real device."); return false; }