I am trying to implement GCM Push notification and try to get Android emulator id, and add the following code, but it shows me the following error. I cam relatively new on this platform.
public class MainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String android_id= Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
}
getContext() method available in View class. Use MainActivity.this
to access getContentResolver
method:
String android_id= Settings.Secure.getString(MainActivity.this.getContentResolver(),
Settings.Secure.ANDROID_ID)
Hey here is the solution for your question:-
You are using activity so You don't need to use
getcontext()
orthis
Just use below line of code to get you the string:-
String string =Settings.Secure.getString( getContentResolver(),Settings.Secure.ANDROID_ID);
You can use this
String android_id= Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With