List of usage examples for android.telephony TelephonyManager getDeviceId
@Deprecated
@SuppressAutoDoc
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getDeviceId()
From source file:tw.com.sti.store.api.android.AndroidApiService.java
private AndroidApiService(Context context, Configuration config) { this.config = config; this.apiUrl = new ApiUrl(config); if (Logger.DEBUG) L.d("new ApiService()"); sdkVer = Build.VERSION.SDK;/*www .j a v a 2s .c o m*/ sdkRel = Build.VERSION.RELEASE; try { PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES); storeId = pi.packageName; clientVer = "" + pi.versionCode; } catch (NameNotFoundException e) { } TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); deviceId = tm.getDeviceId() == null ? "0" : tm.getDeviceId(); macAddress = NetworkUtils.getDeviceMacAddress(context); subscriberId = tm.getSubscriberId() == null ? "0" : tm.getSubscriberId(); simSerialNumber = tm.getSimSerialNumber() == null ? "0" : tm.getSimSerialNumber(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); try { Class<Display> cls = Display.class; Method method = cls.getMethod("getRotation"); Object retobj = method.invoke(display); int rotation = Integer.parseInt(retobj.toString()); if (Surface.ROTATION_0 == rotation || Surface.ROTATION_180 == rotation) { wpx = "" + display.getWidth(); hpx = "" + display.getHeight(); } else { wpx = "" + display.getHeight(); hpx = "" + display.getWidth(); } } catch (Exception e) { if (display.getOrientation() == 1) { wpx = "" + display.getHeight(); hpx = "" + display.getWidth(); } else { wpx = "" + display.getWidth(); hpx = "" + display.getHeight(); } } SharedPreferences pref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); // token = pref.getString(PREF_KEY_TOKEN, ""); // uid = pref.getString(PREF_KEY_UID, ""); // userId = pref.getString(PREF_KEY_USER_ID, ""); appFilter = pref.getInt(PREF_KEY_APP_FILTER, 0); // ipLoginEnable = pref.getBoolean(PREF_KEY_IP_LOGIN_ENABLE, true); // ??SIM? String pref_subscriberId = pref.getString(PREF_KEY_SUBSCRIBER_ID, "0"); String pref_simSerialNumber = pref.getString(PREF_KEY_SIM_SERIAL_NUMBER, "0"); if (!subscriberId.equals(pref_subscriberId) || !simSerialNumber.equals(pref_simSerialNumber)) { if (Logger.DEBUG) L.d("Change SIM card."); cleanCredential(context); } this.getCredential(context); }
From source file:com.prey.PreyPhone.java
private String getUuid() { String uuid = ""; TelephonyManager tManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); try {/*from w w w. j a v a 2 s . com*/ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ctx.checkSelfPermission( android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) { uuid = tManager.getDeviceId(); } } else { uuid = tManager.getDeviceId(); } } catch (Exception e) { PreyLogger.e("Error getUuid:" + e.getMessage(), e); } return uuid; }
From source file:com.android.server.MaybeService.java
private String getDeviceMEID() { if (mDeviceMEID == null) { TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); mDeviceMEID = tm.getDeviceId(); Log.d(TAG, "Device MEID:" + mDeviceMEID); }/* w ww. j a v a 2 s.co m*/ return mDeviceMEID; }
From source file:com.mozilla.SUTAgentAndroid.SUTAgentAndroid.java
/** Called when the activity is first created. */ @Override/*from www . j a v a 2s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); fixScreenOrientation(); DoCommand dc = new DoCommand(getApplication()); Log.i("SUTAgentAndroid", dc.prgVersion); dc.FixDataLocalPermissions(); // Get configuration settings from "ini" file File dir = getFilesDir(); File iniFile = new File(dir, "SUTAgent.ini"); String sIniFile = iniFile.getAbsolutePath(); String lc = dc.GetIniData("General", "LogCommands", sIniFile); if (lc != "" && Integer.parseInt(lc) == 1) { SUTAgentAndroid.LogCommands = true; } SUTAgentAndroid.RegSvrIPAddr = dc.GetIniData("Registration Server", "IPAddr", sIniFile); SUTAgentAndroid.RegSvrIPPort = dc.GetIniData("Registration Server", "PORT", sIniFile); SUTAgentAndroid.HardwareID = dc.GetIniData("Registration Server", "HARDWARE", sIniFile); SUTAgentAndroid.Pool = dc.GetIniData("Registration Server", "POOL", sIniFile); SUTAgentAndroid.sTestRoot = dc.GetIniData("Device", "TestRoot", sIniFile); SUTAgentAndroid.Abi = android.os.Build.CPU_ABI; log(dc, "onCreate"); dc.SetTestRoot(SUTAgentAndroid.sTestRoot); Log.i("SUTAgentAndroid", "Test Root: " + SUTAgentAndroid.sTestRoot); tv = (TextView) this.findViewById(R.id.Textview01); if (getLocalIpAddress() == null) setUpNetwork(sIniFile); String macAddress = "Unknown"; if (android.os.Build.VERSION.SDK_INT > 8) { try { NetworkInterface iface = NetworkInterface .getByInetAddress(InetAddress.getAllByName(getLocalIpAddress())[0]); if (iface != null) { byte[] mac = iface.getHardwareAddress(); if (mac != null) { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); for (int i = 0; i < mac.length; i++) { f.format("%02x%s", mac[i], (i < mac.length - 1) ? ":" : ""); } macAddress = sUniqueID = sb.toString(); } } } catch (UnknownHostException ex) { } catch (SocketException ex) { } } else { // Fall back to getting info from wifiman on older versions of Android, // which don't support the NetworkInterface interface WifiManager wifiMan = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifiMan != null) { WifiInfo wifi = wifiMan.getConnectionInfo(); if (wifi != null) macAddress = wifi.getMacAddress(); if (macAddress != null) sUniqueID = macAddress; } } if (sUniqueID == null) { BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter(); if ((ba != null) && (ba.isEnabled() != true)) { ba.enable(); while (ba.getState() != BluetoothAdapter.STATE_ON) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } sUniqueID = ba.getAddress(); ba.disable(); while (ba.getState() != BluetoothAdapter.STATE_OFF) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } else { if (ba != null) { sUniqueID = ba.getAddress(); sUniqueID.toLowerCase(); } } } if (sUniqueID == null) { TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); if (mTelephonyMgr != null) { sUniqueID = mTelephonyMgr.getDeviceId(); if (sUniqueID == null) { sUniqueID = "0011223344556677"; } } } String hwid = getHWID(this); sLocalIPAddr = getLocalIpAddress(); Toast.makeText(getApplication().getApplicationContext(), "SUTAgent [" + sLocalIPAddr + "] ...", Toast.LENGTH_LONG).show(); String sConfig = dc.prgVersion + lineSep; sConfig += "Test Root: " + sTestRoot + lineSep; sConfig += "Unique ID: " + sUniqueID + lineSep; sConfig += "HWID: " + hwid + lineSep; sConfig += "ABI: " + Abi + lineSep; sConfig += "OS Info" + lineSep; sConfig += "\t" + dc.GetOSInfo() + lineSep; sConfig += "Screen Info" + lineSep; int[] xy = dc.GetScreenXY(); sConfig += "\t Width: " + xy[0] + lineSep; sConfig += "\t Height: " + xy[1] + lineSep; sConfig += "Memory Info" + lineSep; sConfig += "\t" + dc.GetMemoryInfo() + lineSep; sConfig += "Network Info" + lineSep; sConfig += "\tMac Address: " + macAddress + lineSep; sConfig += "\tIP Address: " + sLocalIPAddr + lineSep; displayStatus(sConfig); sRegString = "NAME=" + sUniqueID; sRegString += "&IPADDR=" + sLocalIPAddr; sRegString += "&CMDPORT=" + 20701; sRegString += "&DATAPORT=" + 20700; sRegString += "&OS=Android-" + dc.GetOSInfo(); sRegString += "&SCRNWIDTH=" + xy[0]; sRegString += "&SCRNHEIGHT=" + xy[1]; sRegString += "&BPP=8"; sRegString += "&MEMORY=" + dc.GetMemoryConfig(); sRegString += "&HARDWARE=" + HardwareID; sRegString += "&POOL=" + Pool; sRegString += "&ABI=" + Abi; String sTemp = Uri.encode(sRegString, "=&"); sRegString = "register " + sTemp; pruneCommandLog(dc.GetSystemTime(), dc.GetTestRoot()); if (!bNetworkingStarted) { Thread thread = new Thread(null, doStartService, "StartServiceBkgnd"); thread.start(); bNetworkingStarted = true; Thread thread2 = new Thread(null, doRegisterDevice, "RegisterDeviceBkgnd"); thread2.start(); } monitorBatteryState(); // If we are returning from an update let'em know we're back Thread thread3 = new Thread(null, doUpdateCallback, "UpdateCallbackBkgnd"); thread3.start(); final Button goButton = (Button) findViewById(R.id.Button01); goButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } }); }
From source file:com.gsbabil.antitaintdroid.UtilityFunctions.java
public Map<String, String> collectPrivateData() { Map<String, String> data = new HashMap<String, String>(); final TelephonyManager tm = (TelephonyManager) MyApp.context.getSystemService(Context.TELEPHONY_SERVICE); // final String androidId = Secure.getString( // MyApp.context.getContentResolver(), Secure.ANDROID_ID); // data.put("AndroidId", androidId); // data.put("Line1Number", tm.getLine1Number()); // data.put("CellLocation", tm.getCellLocation().toString()); // data.put("SimSerialNumber", tm.getSimSerialNumber()); // data.put("SimOperatorName", tm.getNetworkOperatorName()); // data.put("SubscriberId", tm.getSubscriberId()); data.put("DeviceId", tm.getDeviceId()); // data.put("Microphone", getMicrophoneSample()); // data.put("Camera", getCameraSample()); // data.put("Accelerometer", getAccelerometerSample()); return data;//from ww w . j a va 2s . c om }
From source file:hu.fnf.devel.atlas.Atlas.java
@SuppressWarnings("deprecation") @SuppressLint("WorldReadableFiles") private void initData() { if (AtlasData.config == null) { AtlasData.config = getSharedPreferences("prefs", FragmentActivity.MODE_WORLD_READABLE); }//from w ww. j a v a2 s. co m data = (AtlasData) getLastCustomNonConfigurationInstance(); if (data == null) { String uuid = null; Log.d("onCreate", "new begining..."); try { TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); if (tManager.getDeviceId() != null) { Log.d("Atlas", "SN:" + String.format("%1$24s", tManager.getDeviceId())); uuid = String.format("%1$24s", tManager.getDeviceId()); // DESede key is 24 byte long } else { uuid = "iereileiphah3Eihoh8EeH2a"; } } catch (Exception e) { Log.e("Atlas", "no such algorithm " + e.getMessage()); e.printStackTrace(); } data = new AtlasData(AtlasData.CATEGORY, AtlasData.PSUMMARY, uuid); } else { Log.d("onCreate", "restoring..."); Log.d("onCreate", "view level: " + AtlasData.peekPos().level); Log.d("onCreate", "page level: " + AtlasData.peekPos().page); } }
From source file:org.ednovo.goorusearchwidget.ResourcePlayer.java
@Override protected void onStart() { super.onStart(); TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); imeicode = tm.getDeviceId(); new httppoststart().execute(); start_time = System.currentTimeMillis(); if (flag_isPlayerTransition) { flag_isPlayerTransition = false; resourceType = ""; resourceGooruId = ""; }/* w w w.ja v a2 s . c om*/ Log.i("onStartSearchRes", "onStart"); }
From source file:com.tomi.ginatask.MainActivity.java
private void showDeviceInfoDialog() { TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); AlertDialog.Builder builder = new AlertDialog.Builder(this); IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = this.registerReceiver(null, intentFilter); int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); float batteryPct = (level / (float) scale) * 100; int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL; builder.setTitle("Device info") .setMessage("IMEI: " + telephonyManager.getDeviceId() + "\n\nBattery level: " + batteryPct + "% " + (isCharging ? "(charging)" : "(not charging)")) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { }//from w w w . j a v a 2 s .c om }).show(); }
From source file:com.septrivium.augeo.ui.SipHome.java
private void startAppFlow() { TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); final String deviceID = telephonyManager.getDeviceId(); AuGeoServiceFlowManager.getInstance().startServices(this, deviceID); }