mytechead

Android & Wordpress Help center

How to get ANDROID_ID of an android device?

This tutorial explains how to get ANDROID_ID of android devices.

ANDROID_ID is a unique string that can be used to identify your device. Though there are many pros and cons of the same. Some properties of ANDROID_ID are :

1) This is a 64-bit quantity that is generated and stored when the device first boots.
2) It is reset when the device is wiped.
3) It is not 100% reliable on releases of Android prior to 2.2 (“Froyo”).
4) Also, there has been at least one widely-observed bug in a popular handset from a major manufacturer, where every instance has the same ANDROID_ID.

So developers are adviced to use it keeping in mind all the above mentioned points.

The code below can be used to obtain ANDROID_ID :


String android_id = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);


Advertisements

Single Post Navigation

4 thoughts on “How to get ANDROID_ID of an android device?

  1. how in the world do I use this code. I’m completely lost…

    • Heya… Create an activity in your project and try using something like this :

      import android.app.Activity;
      import android.os.Bundle;
      import android.provider.Settings.Secure;
      import android.widget.Toast;


      public class YourAndroidActivityName extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.test_clearable_edit_text);

      String android_id = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
      Toast.makeText(getApplicationContext(), "ANDROID ID = " + android_id, Toast.LENGTH_LONG).show();

      }
      }

  2. Im trying to get my droid ex id number but I have no clue…..Help…

    • Heya… Create an activity in your project and try using something like this :


      import android.app.Activity;
      import android.os.Bundle;
      import android.provider.Settings.Secure;
      import android.widget.Toast;

      public class YourAndroidActivityName extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.test_clearable_edit_text);

      String android_id = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
      Toast.makeText(getApplicationContext(), "ANDROID ID = " + android_id, Toast.LENGTH_LONG).show();

      }
      }

      In emulator this will return Null, but in actual devices it will return ANDROID_ID.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: