Android find device number

Android device ID

Бывает возникает необходимость получить какой-то уникальный идентификатор для Android телефона. Какие могут быть варианты? В данном топике опишу семь известных мне способов сделать это. (Точее, способов будет шесть, а вот седьмой как вариант – это комбинация всех шести предыдущих). Итак.

Android IMEI.
Думаю, Вам известно, что каждый, даже самый старый черно-белый телефон, имеет свой уникальный идентификатор – IMEI (International Mobile Equipment Identity), применяемый по большей степени в GSM сетях. Он устанавливается производителем телефона и хранится в прошивке. Можем его смело использовать в качестве требуемого идентификатора:

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String devicIMEI = telephonyManager.getDeviceId();

Для эмулятора всегда возвращается «000000000000000″, для реального телефона что-то наподобие «351256985671943″

Phone Number
Следующим образом можем получить номер телефона:

String phoneNumber = telephonyManager.getLine1Number();

Вернет строку вида: +ХХХХХХХХХХХХ (Х = [0..9])

Примечание: предыдущие два примера требуют указания в манифесте следующего пермишина:
android.permission.READ_PHONE_STATE

Псевдо-уникальный ID
Не все андроид-девайсы могут быть оснащены GSM-модулем, скажем, зато у всех у них есть производитель, который «слепил» устройство из всяких железок. Вот какраз информация об этих железках, собранная вместе, и может послужить в качестве уникального идентификатора (правда возможны и повторения). В некоторых случаях может пригодиться. Сконструируем из этих данных что-то похожее на IMEI телефона (15 знаков):

String pseudoID = «35″ +
Build.BOARD.length()%10 + Build.BRAND.length()%10 +
Build.CPU_ABI.length()%10 + Build.DEVICE.length()%10 +
Build.DISPLAY.length()%10 + Build.HOST.length()%10 +
Build.ID.length()%10 + Build.MANUFACTURER.length()%10 +
Build.MODEL.length()%10 + Build.PRODUCT.length()%10 +
Build.TAGS.length()%10 + Build.TYPE.length()%10 +
Build.USER.length()%10;

Android ID
Это еще один ID. Считается ненадежным, так как может в некоторых случаях быть и null. Обратимся к документации:
A 64-bit number (as a hex string) that is randomly generated on the device’s first boot and should remain constant for the lifetime of the device.
Ничего, пригодится:

String androidID = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

Wi-Fi Mac адрес
В качестве уникального Device Id можно использовать Mac Wi-Fi-адаптера. Для его получения необходимо в манифесте установить права: android.permission.ACCESS_WIFI_STATE

WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
String wifiMac = wifiManager.getConnectionInfo().getMacAddress();

Androif BlueTooth ID
По аналогии с Wi-Fi мак-адресом, может взять и голубозубый мак. (требуются права android.permission.BLUETOOTH и, возможно, включенный адаптер)

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
String blueToothMac = bluetoothAdapter.getAddress();

Номер 7
Вариация всех предыдущих методов. Самый простой вариант – получить все вышеописанные идентификаторы, сложить в одну строку и взять md5 хеш от этой строки.

Источник

2 Easy Ways To Find Android Device ID and Change It

The android device ID is a unique alphanumeric code generated for your Android phone when you first set it up. This code basically identifies your device similar to how the IMEI number works. However, Android device ID is specifically used for identification purposes, instead of tracking your device. For example, apps with free limited trial periods use the Android device ID to identify your device and ensure you don’t use the app after the trial period ends.

If you need to provide your Android device ID to someone for identification, then I know two ways to get device ID on Android. On top of that, I’ll also show you how to change your Android device ID if you don’t want someone to identify your device. Keep reading and you’ll find two ways to both find and change Android device ID.

Читайте также:  Что такое viewmodel android

How to find Android device ID

There are two ways to find Android device ID, you can use a dial pad code or a third-party app. One of these methods should work for you.

Method 1: Find Android device ID using dial pad code

You can use a simple dial pad code to instantly see your phone’s device ID. Here’s how to use a dial pad code to find Android device ID:

1. Open your phone’s dial pad, usually named “Phone” in the apps drawer.

2. Here dial this code *#*#8255#*#*. As soon as you will enter the last digit, Gtalk Service Monitor will open up and show your Android device ID along with your email.

Do keep in mind that this method may not work on some Android devices, particularly new Samsung devices.

Method 2: Use the Device ID app to find Android device ID

If the above method didn’t work, then you’ll have to depend on a third-party app. Although there are many such apps, but I particularly like Device ID by Evozi for its extensive information and ease of use.

Just download the Device ID app and launch it. Your phone’s device ID will be shown at the top along with a plethora of other important information, such as IMEI or MAC address.

You can tap on “Android Device ID” to see options to copy or directly share the device ID with anyone you like.

Good to know: Your information is safe and won’t leave your phone while using this app. The app doesn’t require internet permission, so it can’t send any information collected.

How to change Android device ID

If someone has your device ID and you don’t want them to identify your device, then you can also get a new Android device ID. Usually, this is done when your Android phone is banned from a specific app or service. Whatever your reason, below I have provided two ways to change Android device ID for both rooted and unrooted users.

Method 1: Change Android device ID without root

If you don’t have a rooted device, then it would be a little difficult to change the device ID. You’ll have to fully format your device data to change your Android phone’s device ID. As the device ID is generated when you first set up the device, resetting the phone will change the Android device ID automatically.

Note: A factory reset will delete all the data on your phone, including contacts, app data, settings and media files. Make sure all your important data is backed up somewhere safe before you go through the below process.

1. Go to the phone “Settings” and tap on the “General management” option.

2. Here tap on “Reset” and then select “Factory data reset”.

3. Now scroll down and tap on “Reset Device” and then tap on “Delete All” to start the reset process.

It will take 5-10 mins to reset your phone and then you’ll have to set up your phone again. You can use any of the aforementioned methods to check whether the Android device ID has successfully changed or not. The device ID of your Android tablet can be helpful if you have problems with your phone. You will need to contact customer service to resolve the problem when asked for device ID details.

Читайте также:  Драйвер для adb android debug bridge

Method 2: Use the Android device ID changer app to change the device ID

If you have a rooted device, then changing the device ID is just a two-tap process. You can use any reliable Android device ID changer app and it will change the device ID with a random one with just two taps. I have tried multiple apps for this purpose and Device ID Changer by Silver Lab seems most trustable to me. If you don’t mind a few non-intrusive ads, then go for this free app. Here’s how to use it:

1. Install the Device ID Changer app and launch it.

2. Tap on the “Random” button in the “Edit” section to generate a random device ID.

3. Afterwards, tap on the “Go” button to immediately change the generated ID with your current one.

To conclude

Finding the device ID isn’t a big problem, but changing it can be a little cumbersome. You should try to go for the built-in methods to find and change Android device ID. However, be assured that both the third-party apps I have introduced here are safe and can’t connect to the internet to steal your information. If needed, you should use these apps with peace of mind.

If you have any questions, let us know in the comments below.

Источник

How to find serial number of Android device?

I need to use a unique ID for an Android app and I thought the serial number for the device would be a good candidate. How do I retrieve the serial number of an Android device in my app ?

18 Answers 18

getSystemService is a method from the Activity class. getDeviceID() will return the MDN or MEID of the device depending on which radio the phone uses (GSM or CDMA).

Each device MUST return a unique value here (assuming it’s a phone). This should work for any Android device with a sim slot or CDMA radio. You’re on your own with that Android powered microwave 😉

As Dave Webb mentions, the Android Developer Blog has an article that covers this.

I spoke with someone at Google to get some additional clarification on a few items. Here’s what I discovered that’s NOT mentioned in the aforementioned blog post:

  • ANDROID_ID is the preferred solution. ANDROID_ID is perfectly reliable on versions of Android =2.3. Only 2.2 has the problems mentioned in the post.
  • Several devices by several manufacturers are affected by the ANDROID_ID bug in 2.2.
  • As far as I’ve been able to determine, all affected devices have the same ANDROID_ID, which is 9774d56d682e549c. Which is also the same device id reported by the emulator, btw.
  • Google believes that OEMs have patched the issue for many or most of their devices, but I was able to verify that as of the beginning of April 2011, at least, it’s still quite easy to find devices that have the broken ANDROID_ID.

Based on Google’s recommendations, I implemented a class that will generate a unique UUID for each device, using ANDROID_ID as the seed where appropriate, falling back on TelephonyManager.getDeviceId() as necessary, and if that fails, resorting to a randomly generated unique UUID that is persisted across app restarts (but not app re-installations).

This code returns device serial number using a hidden Android API.

Although, it is not guaranteed that the Android ID will be an unique identifier.

Читайте также:  Best android ebooks app

It recommends against using TelephonyManager.getDeviceId() as it doesn’t work on Android devices which aren’t phones such as tablets, it requires the READ_PHONE_STATE permission and it doesn’t work reliably on all phones.

Instead you could use one of the following:

  • Mac Address
  • Serial Number
  • ANDROID_ID

The post discusses the pros and cons of each and it’s worth reading so you can work out which would be the best for your use.

For a simple number that is unique to the device and constant for its lifetime (barring a factory reset or hacking), use Settings.Secure.ANDROID_ID.

To use the device serial number (the one shown in «System Settings / About / Status») if available and fall back to Android ID:

The IMEI is good but only works on Android devices with phone. You should consider support for Tablets or other Android devices as well, that do not have a phone.

You have some alternatives like: Build class members, BT MAC, WLAN MAC, or even better — a combination of all these.

I have explained these details in an article on my blog, see: http://www.pocketmagic.net/?p=1662

Since no answer here mentions a perfect, fail-proof ID that is both PERSISTENT through system updates and exists in ALL devices (mainly due to the fact that there isn’t an individual solution from Google), I decided to post a method that is the next best thing by combining two of the available identifiers, and a check to chose between them at run-time.

Before code, 3 facts:

TelephonyManager.getDeviceId() (a.k.a.IMEI) will not work well or at all for non-GSM, 3G, LTE, etc. devices, but will always return a unique ID when related hardware is present, even when no SIM is inserted or even when no SIM slot exists (some OEM’s have done this).

Since Gingerbread (Android 2.3) android.os.Build.SERIAL must exist on any device that doesn’t provide IMEI, i.e., doesn’t have the aforementioned hardware present, as per Android policy.

Due to fact (2.), at least one of these two unique identifiers will ALWAYS be present, and SERIAL can be present at the same time that IMEI is.

SOLUTION

With the facts above, one can always have a unique identifier by checking if there is IMEI-bound hardware, and fall back to SERIAL when it isn’t, as one cannot check if the existing SERIAL is valid. The following static class presents 2 methods for checking such presence and using either IMEI or SERIAL:

I would advice on using getCleartextID_HARDCHECK . If the reflection doesn’t stick in your environment, use the getCleartextID_SIMCHECK method instead, but take in consideration it should be adapted to your specific SIM-presence needs.

P.S.: Do please note that OEM’s have managed to bug out SERIAL against Google policy (multiple devices with same SERIAL), and Google as stated there is at least one known case in a big OEM (not disclosed and I don’t know which brand it is either, I’m guessing Samsung).

Disclaimer: This answers the original question of getting a unique device ID, but the OP introduced ambiguity by stating he needs a unique ID for an APP. Even if for such scenarios Android_ID would be better, it WILL NOT WORK after, say, a Titanium Backup of an app through 2 different ROM installs (can even be the same ROM). My solution maintains persistence that is independent of a flash or factory reset, and will only fail when IMEI or SERIAL tampering occurs through hacks/hardware mods.

Источник

Оцените статью