Integración de GCM para Android

Aunque hice toda la instrucción en la página de los reveladores de Google para el Gcm (ajustes del manifiesto, archivo de configuración, registro en la consola …)

public class MyInstanceIDListenerService extends IntentService { private static final String TAG = "RegIntentService"; private static final String[] TOPICS = {"global"}; public MyInstanceIDListenerService() { super(TAG); } @Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try { // [START register_for_gcm] // Initially this call goes out to the network to retrieve the token, subsequent calls // are local. // [START get_token] InstanceID instanceID = InstanceID.getInstance(this); String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); // [END get_token] Log.i(TAG, "GCM Registration Token: " + token); // TODO: Implement this method to send any registration to your app's servers. sendRegistrationToServer(token); // Subscribe to topic channels subscribeTopics(token); // You should store a boolean that indicates whether the generated token has been // sent to your server. If the boolean is false, send the token to your server, // otherwise your server should have already received the token. sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply(); // [END register_for_gcm] } catch (Exception e) { Log.d(TAG, "Failed to complete token refresh", e); // If an exception happens while fetching the new token or updating our registration data // on a third-party server, this ensures that we'll attempt the update at a later time. sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply(); } // Notify UI that registration has completed, so the progress indicator can be hidden. Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); } /** * Persist registration to third-party servers. * * Modify this method to associate the user's GCM registration token with any server-side account * maintained by your application. * * @param token The new token. */ private void sendRegistrationToServer(String token) { // Add custom implementation, as needed. } /** * Subscribe to any GCM topics of interest, as defined by the TOPICS constant. * * @param token GCM token * @throws IOException if unable to reach the GCM PubSub service */ // [START subscribe_topics] private void subscribeTopics(String token) throws IOException { for (String topic : TOPICS) { GcmPubSub pubSub = GcmPubSub.getInstance(this); pubSub.subscribe(token, "/topics/" + topic, null); } } // [END subscribe_topics] 

}

Gcm_defaultSenderId y QuickStartPreferences no se pueden resolver. Por qué ?? ¿Cómo puedo superarlo?

gcm_defaultSenderId es una cadena que debe crear. Es el ID del remitente de la aplicación.

QuickStartPreferences sirve como un ejemplo. Es una clase que puede crear para mantener las claves de preferencia, si desea recordar que el token se ha enviado a su servidor (consulte el comentario sobre esta línea).

  • No se puede resolver el símbolo 'GoogleCloudMessaging' GCM
  • Java.lang.SecurityException: Nombre del paquete de llamadas desconocido, com.google.android.gms.common.internal.zzs
  • ¿El mensaje de GCM se está reemplazando?
  • Mensaje de error de PHP GCM MismatchSenderId
  • ID de registro GCM de Android longitud máxima
  • Android parse push notificación y nuevo GCM generar token de dispositivo equivocado y analizar notificación push no funciona
  • Recibir notificación de empuje cuando la aplicación se ha detenido de forma forzada (Android).
  • PARSE: Notificaciones push "deviceToken" undefined
  • Actualización de token de GCM y cuándo enviar el token al servidor
  • Registro de GCM pero no recibe mensajes en pre 4.0.4. Dispositivos
  • GCM, Android, iOS, utilizando la misma ID de remitente y clave de servidor / clave de autorización
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.