How to obtain the unique identification code of the Android system _android

Source: Internet
Author: User

The example in this article describes the method for acquiring the unique identification code for the Android system. Share to everyone for your reference. Specifically as follows:

On the computer, we used to use the MAC address to flag a computer. On Android devices, you can use Imie or an Android ID to flag a device.

Take a look at how Android gets this information.

One is Telephonymanager's Getdeviceid, the other one is Settings.system's android_id.

Here is a piece of test code:

Package Com.npc4.android.imie;
Import android.app.Activity;
Import Android.content.Context;
Import Android.os.Bundle;
Import Android.telephony.TelephonyManager;
Import Android.util.Log;
Import Android.provider.Settings.System;
/**
 * @author Lixinso
 * Get the unique identification of the system/public
class Imie extends activity {
   @Override
  public void OnCreate (Bundle savedinstancestate) {
    super.oncreate (savedinstancestate);
    Setcontentview (r.layout.main);
    Getimiestatus ();
    Getandroidid ();
  }
private void Getimiestatus () {
Telephonymanager TM = (Telephonymanager) this.getsystemservice (context.telephony_ SERVICE);
String deviceId = Tm.getdeviceid ();
LOG.E ("device_id", DeviceId + "");
}
private void Getandroidid () {
String Androidid = system.getstring (Getcontentresolver (), system.android_id);
LOG.E ("android_id", Androidid + "");
}


Tm.getdeviceid () represents a unique device ID, for example, for GSM phone return IMEI, for CDMA phone return MEID, if the device is not available to return null, such as in the simulator.

System.getstring (Getcontentresolver (), system.android_id) represents a 64-digit number that is randomly generated at the first time the device is started and is unchanged throughout the device's lifecycle. (may change if the factory settings are restarted)

I hope this article will help you with your Android program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.