所以我创建了一个类来检索用户设备的 Google 广告 ID。我仍然得到一个空指针。我跟着这个问题
然而它仍然没有工作。这是我的课程代码
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
public class GAID extends AppCompatActivity {
public String mUserId;
public GAID() {
new Thread(new Runnable() {
public void run() {
try {Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
mUserId = adInfo.getId();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gaid);
}
public String getGAID() {
return mUserId;
}