【发布时间】:2014-04-30 04:48:14
【问题描述】:
我正在尝试从 Google Play 服务 API 获取广告 ID。这是一个示例代码:
...
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
...
public class MyActivity extends Activity {
@Override
protected void onStart() {
super.onStart();
Thread thr = new Thread(new Runnable() {
@Override
public void run() {
try {
Context ctx = MyActivity.this.getApplicationContext();
AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(ctx);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
});
thr.start();
synchronized (thr) {
try {
thr.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
当我调用 getAdvertisingIdInfo 方法时,应用程序永远挂起(无论是否使用调试器)。
我正在使用 Windows ADT 22.3、Android SDK API 19、Google Play SDK rev。 16、Android 4.4.2 Nexus 设备。我正在集成 API,如下所述:https://developer.android.com/google/play-services/id.html
可能是什么原因?
【问题讨论】:
标签: android google-play-services ads freeze