import android.content.Context;
import android.provider.Settings;
public class getdeviceid {
public void getAndroidID(Context context) {
String android_id= Settings.System.getString(context.getContentResolver(),
Settings.Secure.ANDROID_ID);
System.out.println(android_id);
}
}
解决方法:
像这样为您的应用程序创建上下文
private Context context = this;
将这些行放在onCreate中
String android_id = Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.ANDROID_ID);
Toast.makeText(context, "android_id= " + android_id, Toast.LENGTH_LONG).show();
要了解有关上下文的更多信息,请参阅this link