0

I retrieve the device ID in my main activity by doing:

String UDID = System.getString(this.getContentResolver(), System.ANDROID_ID);

Later in my code I start a new Activity in which I need the UDID as well, but when I run the same line of code it crashes:

01-01 12:20:54.793: ERROR/AndroidRuntime(868): FATAL EXCEPTION: main
01-01 12:20:54.793: ERROR/AndroidRuntime(868): java.lang.NullPointerException
01-01 12:20:54.793: ERROR/AndroidRuntime(868):     at android.content.ContextWrapper.getContentResolver(ContextWrapper.java:91)

I understand that it has to do something with the context, but cant figure out how to fix this. Of course I could do putExtra, but I guess there must be a better way.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
michaelsmith
  • 1,011
  • 1
  • 16
  • 35

1 Answers1

0

Seems to work for me though this is deprecated

 String id_deprecated = System.getString(this.getContentResolver(),      
                                         android.provider.Settings.System.ANDROID_ID);

You should use the ANDROID_ID defined in Settings.Secure

 String id_new =System.getString(this.getContentResolver(), 
                                    android.provider.Settings.Secure.ANDROID_ID);
Rajdeep Dua
  • 11,190
  • 2
  • 32
  • 22