List of usage examples for android.telephony TelephonyManager getDeviceId
@Deprecated
@SuppressAutoDoc
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getDeviceId()
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 a va 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:siarhei.luskanau.gps.tracker.free.utils.Utils.java
public static String getDeviceId(final Context context) { String deviceId = null;// w ww. ja v a 2s .c o m TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null) { deviceId = telephonyManager.getDeviceId(); } if (deviceId == null) { deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); } if (deviceId != null) { deviceId = deviceId.toUpperCase(Locale.ENGLISH); deviceId = deviceId.replace(" ", ""); if (deviceId != null) { for (; deviceId.length() < 15;) { deviceId = "0" + deviceId; } } } return deviceId; }
From source file:Main.java
public static String getDeviceId(Context ctx) { StringBuilder sbuff = new StringBuilder(); TelephonyManager telephonyManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); /*/*w w w.j av a 2s . c o m*/ * getDeviceId() function Returns the unique device ID. * for example,the IMEI for GSM and the MEID or ESN for CDMA phones. */ String imeistring = telephonyManager.getDeviceId(); sbuff.append(imeistring + DELIMITER); /* * getSubscriberId() function Returns the unique subscriber ID, * for example, the IMSI for a GSM phone. */ String imsistring = telephonyManager.getSubscriberId(); sbuff.append(imsistring + DELIMITER); /* * Settings.Secure.ANDROID_ID returns the unique DeviceID * Works for Android 2.2 and above */ String androidId = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID); sbuff.append(androidId); //Log.d("deep link device id", sbuff.toString()+""); return (sbuff.toString()); }
From source file:com.appbackr.android.tracker.Tracker.java
/** * Generates a unique ID for the device. * //from w w w . j a va 2 s .c o m * This function obtain the Unique ID from the phone. The Unique ID consist of * Build.BOARD + Build.BRAND + Build.CPU_ABI * + Build.DEVICE + Build.DISPLAY + Build.FINGERPRINT + Build.HOST * + Build.ID + Build.MANUFACTURER + Build.MODEL + Build.PRODUCT * + Build.TAGS + Build.TYPE + Build.USER; * + IMEI (GSM) or MEID/ESN (CDMA) * + Android-assigned id * * The Android ID may be changed everytime the user perform Factory Reset * I heard that IMEI values might not be unique because phone factory * might reuse IMEI values to cut cost. * * While the ID might be different from the same device, but resetting of the * Android phone should not occur that often. The values should be close * enough. * * @param c android application contact * @return unique ID as md5 hash generated of available parameters from device and cell phone service provider */ private static String getUDID(Context c) { // Get some of the hardware information String buildParams = Build.BOARD + Build.BRAND + Build.CPU_ABI + Build.DEVICE + Build.DISPLAY + Build.FINGERPRINT + Build.HOST + Build.ID + Build.MANUFACTURER + Build.MODEL + Build.PRODUCT + Build.TAGS + Build.TYPE + Build.USER; // Requires READ_PHONE_STATE TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); // gets the imei (GSM) or MEID/ESN (CDMA) String imei = tm.getDeviceId(); // gets the android-assigned id String androidId = Secure.getString(c.getContentResolver(), Secure.ANDROID_ID); // concatenate the string String fullHash = buildParams.toString() + imei + androidId; return md5(fullHash); }
From source file:uk.ac.horizon.ug.exploding.client.logging.LoggingUtils.java
/** * @param context//from w ww. j a va 2 s . c o m */ private static void logHeader(Context context) { TelephonyManager mTelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String imei = mTelephonyMgr.getDeviceId(); // Requires READ_PHONE_STATE try { JSONStringer js = new JSONStringer(); js.object(); js.key("imei"); js.value(imei); js.key("time"); js.value(System.currentTimeMillis()); js.key("package"); js.value(context.getApplicationInfo().packageName); js.key("application"); js.value(context.getApplicationInfo().name); js.key("os.name"); js.value(System.getProperty("os.name")); js.key("os.arch"); js.value(System.getProperty("os.arch")); js.key("os.version"); js.value(System.getProperty("os.version")); PackageManager pm = context.getPackageManager(); try { PackageInfo pi; // Version pi = pm.getPackageInfo(context.getPackageName(), 0); js.key("versionName"); js.value(pi.versionName); js.key("versionCode"); js.value(pi.versionCode); } catch (NameNotFoundException e) { Log.e(TAG, "Checking package info", e); } js.key("phoneModel"); js.value(android.os.Build.MODEL); js.key("androidVersion"); js.value(android.os.Build.VERSION.RELEASE); js.endObject(); log(LOGTYPE_HEADER, js.toString()); } catch (Exception e) { Log.e(TAG, "Creating log data (header)", e); } }
From source file:com.yutong.axxc.parents.view.common.ActivityUtils.java
public static String getIMEI(Context context) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return telephonyManager.getDeviceId(); }
From source file:Main.java
public static String getDeviceInfo(Context context) { try {//www .jav a2s . com org.json.JSONObject json = new org.json.JSONObject(); android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); String device_id = null; if (checkPermission(context, Manifest.permission.READ_PHONE_STATE)) { device_id = tm.getDeviceId(); } String mac = null; FileReader fstream = null; try { fstream = new FileReader("/sys/class/net/wlan0/address"); } catch (FileNotFoundException e) { fstream = new FileReader("/sys/class/net/eth0/address"); } BufferedReader in = null; if (fstream != null) { try { in = new BufferedReader(fstream, 1024); mac = in.readLine(); } catch (IOException e) { } finally { if (fstream != null) { try { fstream.close(); } catch (IOException e) { e.printStackTrace(); } } if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } json.put("mac", mac); if (TextUtils.isEmpty(device_id)) { device_id = mac; } if (TextUtils.isEmpty(device_id)) { device_id = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); } json.put("device_id", device_id); return json.toString(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:org.openremote.android.console.model.PollingHelper.java
/** * Read the device id for send it in polling request url. * /*from w w w .j a v a 2s. c o m*/ * @param context the context */ private static void readDeviceId(Context context) { if (deviceId == null) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (IPAutoDiscoveryClient.isNetworkTypeWIFI) { deviceId = tm.getDeviceId(); } else { deviceId = UUID.randomUUID().toString(); } } }
From source file:eu.geopaparazzi.library.util.Utilities.java
/** * get unique device id.//from ww w . java 2s . c o m * * @param context the context to use. * @return the unique id. */ public static String getUniqueDeviceId(Context context) { String id = null; try { // try to go for the imei TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); id = tm.getDeviceId(); if (id != null) { return id; } } catch (Exception e) { // ignore and try next } try { id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); if (id != null) { return id; } } catch (Exception e) { // ignore and go on } return id; }
From source file:crow.util.Util.java
/** * ?? ?? android_id //from w ww . j a v a 2 s . co m * * @param context * @return null ? ???0 */ public static String getDeviceId(Context context) { TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String imei = telManager.getDeviceId(); if (imei != null) { return imei; } String dv = null; if ((dv = Settings.Secure.getString(context.getContentResolver(), Secure.ANDROID_ID)) != null) { dv = md5(dv).toUpperCase(); } return dv; }