Get IMEI code or/and Mac Address of a Device

半城伤御伤魂 提交于 2019-12-11 01:32:47

问题


I'm implementing an way to unique identify the device.

The architect send me the following specs:

devices with Wifi + 3G: IMEI Code

devices Wifi only - MacAddress

Both needs also the Manufacturer + Model for complete the id.

My questions are:

  1. How do I get the IMEI from the device?

  2. How can I get the Manufacturer and Model from the device? (I see theres some constants on Build class for it, but don't know where to use them)

  3. Theres devices with 3G only?

  4. How can I know if the device is wifi only, wifi+3g or 3g only if exists?

Also, suggestions for unique identifiers are available.

PS: I'm already able to get the MacAddres through WifiManager.


回答1:


You can use the TelephonyManager getDeviceID method. This should return IMEI or MEID. For build information you can see android.os.Build and android.os.Build.VERSION. Also, if its about uniquely identifying your application installs, you may want to go through (and/or show your architect) the developer blog post on Identifying App Installations




回答2:


  1. How to get IMEI can be found in this question: How to get the device's IMEI/ESN programmatically in android?;
  2. MANUFACTURER and MODEL can be retrieved from android.os.BUILD class.
  3. Theoretically, yes, there might be devices without Wi-Fi but with 3G. But I haven't seen any.
  4. If getSystemService(WIFI_SERVICE) returns null, then there is no Wi-Fi.



回答3:


  1. android.telephony.TelephonyManager.getDeviceId() gets you 'the IMEI for GSM and the MEID or ESN for CDMA phones'.

  2. Build.MODEL is a static field, so you can just use it like that, so long as you've imported android.os.Build first.

  3. Quite possibly.

  4. You could try calling Context.getSystemService(Context.WIFI_SERVICE) and seeing if it's null, although I suppose it's possible that the service might still exist even if there's no wifi (in such a case, I would expect checking the wifi to return DISABLED.)




回答4:


These questions have plagued Android developers for a while, see Is there a unique Android device ID?

The Android development team has tried to address these concerns directly in their blog here: http://android-developers.blogspot.com/2011/03/identifying-app-installations.html

In answer to your last question: just test for null when querying for SIM/MAC/Whatever and then act accordingly. It's been reported that there are cases where MAC will return null; see my first link.



来源:https://stackoverflow.com/questions/6033511/get-imei-code-or-and-mac-address-of-a-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!