Werfen Sie einen Blick auf GCM's project MainActivty auf GitHub, sehr einfach & Einfach.
Um genau zu sein, müssen Sie RegistrationIntentSerice
nennen, wenn checkPlayServices()
wahr ist ..
private boolean checkPlayServices() {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
.show();
} else {
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
Nach der Erklärung checkPlayServices()
Methode Sie wahr wenn es überprüfen müssen und den Dienst ausführen:
if (checkPlayServices()) {
// Start IntentService to register this application with GCM.
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
}
Meine Implementierung ist nicht viel anders. Ich rufe 'startService (intent) 'von' MainActivity' auf, aber 'onHandleIntent' wird nie aufgerufen –