Ich versuche, Werbe-ID von Google Play-Services-API zu erhalten. Hier ist ein Beispielcode:AdvertisingIdClient getAdvertisingIdInfo hängt immer
...
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();
}
}
}
}
Wenn ich getAdvertisingIdInfo Methode bin Aufruf Anwendung hängt für immer (egal mit Debugger oder nicht).
Ich verwende Windows ADT 22,3, API 19 Android SDK, Google SDK rev spielen. 16, Android 4.4.2 Nexus-Geräte. Ich Integration API wie hier beschrieben: https://developer.android.com/google/play-services/id.html
Was ein Grund sein könnte?
Ich stimme zu, Googles Beispielcode darauf ist piss arm! –
und wenn ich ihrem Dokument folge, bekomme ich einen schönen Phat Flusen Fehler 'Unreachable Catch Block für GooglePlayServicesAvailabilityException. Diese Ausnahme wird niemals aus dem try-Anweisung body geworfen. In meinem ganzen Leben als Windows-Entwickler hat Microsoft zumindest ihre Sachen ordentlich dokumentiert - und erlaubt Rückmeldungen zu den Dokumenten! FFS –
Oder besser, verwenden Sie eine AsyncTask. – RominaV