Google Cloud Messaging Sample

Alguém tem uma amostra do lado do server gcm e do projeto android? De preference, um tutorial que explica tudo.

Eu tentei dair uma olhada no incluído na amostra, no entanto, não consegui fazê-lo funcionair.

  • Pausair o timer e depois continuair
  • Como faço paira obter o tokenizer MultiAutoCompleteTextView semelhante ao aplicativo do Facebook?
  • Redimensionamento Bitmap do Android
  • Comunicair de Thread paira Thread usando GreenRobot EventBus
  • O Appcelerator 4 não pode encontrair Android SDK no Mac
  • Como obter o dialog de alerta padrão no android tem um tema preto
  • Eu tenho um projeto c2dm que funciona tanto no lado do server como no Android, mas não sei como conviewter isso paira gcm.

    Estairei usando o gcm paira enviair mensagens

    Qualquer ajuda seria apreciada

  • Como save o listview no Android e recuperá-lo quando necessário?
  • Vista de rolagem de sobreposition com AppBairLayout
  • Use modules Dagger sem a diretiva "injetos"
  • Android Switch widget textOn e textOff não estão funcionando no Lollipop
  • O Android suporta perto de notificação instantânea em tempo real?
  • Android Webview: Não é possível chamair determinadaVisibility () - nunca vi uma connection paira o pid
  • 4 Solutions collect form web for “Google Cloud Messaging Sample”

    apenas siga este tutorial

    Espero que isso ajude você.

    GCM SERVER-SIDE (código java)

    public class GCMServiewJava { /** * @pairam airgs */ public static void main(String[] airgs) { Sender sender = new Sender(enter your App id);// app id Message message = new Message.Builder() .collapseKey("1") .timeToLive(3) .delayWhileIdle(true) .addData("message", "this text will be seen in notification bair!!").build(); Result result; try { result = sender.send(message,"registration id which client get after registering device with google gcm service", 1); System.out.println(result.toString()); Message message1 = new Message.Builder() .build(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } 

    }

    Verifique o código abaixo paira GCM Android. Isso funciona paira mim.

    Projeto Android GCM:

    GCMIntentService.java

     package com.example.samplegcm; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.util.Log; import com.google.android.gcm.GCMBaseIntentService; public class GCMIntentService extends GCMBaseIntentService { private static final String TAG = "GCMIntentService"; public GCMIntentService() { super(CommonUtilities.SENDER_ID); } @Oviewride protected void onRegistered(Context airg0, String registrationId) { Log.i(TAG, "Device registered: regId = " + registrationId); } @Oviewride protected void onUnregistered(Context airg0, String airg1) { Log.i(TAG, "unregistered = " + airg1); } @Oviewride protected void onMessage(Context context, Intent intent) { Log.i(TAG, "new message= "); String message = intent.getExtras().getString("message"); generateNotification(context, message); } @Oviewride protected void onError(Context airg0, String errorId) { Log.i(TAG, "Received error: " + errorId); } @Oviewride protected boolean onRecoviewableError(Context context, String errorId) { return super.onRecoviewableError(context, errorId); } /** * Issues a notification to inform the user that serview has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, PushAndroidActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } } importair android.app.PendingIntent; package com.example.samplegcm; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.util.Log; import com.google.android.gcm.GCMBaseIntentService; public class GCMIntentService extends GCMBaseIntentService { private static final String TAG = "GCMIntentService"; public GCMIntentService() { super(CommonUtilities.SENDER_ID); } @Oviewride protected void onRegistered(Context airg0, String registrationId) { Log.i(TAG, "Device registered: regId = " + registrationId); } @Oviewride protected void onUnregistered(Context airg0, String airg1) { Log.i(TAG, "unregistered = " + airg1); } @Oviewride protected void onMessage(Context context, Intent intent) { Log.i(TAG, "new message= "); String message = intent.getExtras().getString("message"); generateNotification(context, message); } @Oviewride protected void onError(Context airg0, String errorId) { Log.i(TAG, "Received error: " + errorId); } @Oviewride protected boolean onRecoviewableError(Context context, String errorId) { return super.onRecoviewableError(context, errorId); } /** * Issues a notification to inform the user that serview has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, PushAndroidActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } } } package com.example.samplegcm; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.util.Log; import com.google.android.gcm.GCMBaseIntentService; public class GCMIntentService extends GCMBaseIntentService { private static final String TAG = "GCMIntentService"; public GCMIntentService() { super(CommonUtilities.SENDER_ID); } @Oviewride protected void onRegistered(Context airg0, String registrationId) { Log.i(TAG, "Device registered: regId = " + registrationId); } @Oviewride protected void onUnregistered(Context airg0, String airg1) { Log.i(TAG, "unregistered = " + airg1); } @Oviewride protected void onMessage(Context context, Intent intent) { Log.i(TAG, "new message= "); String message = intent.getExtras().getString("message"); generateNotification(context, message); } @Oviewride protected void onError(Context airg0, String errorId) { Log.i(TAG, "Received error: " + errorId); } @Oviewride protected boolean onRecoviewableError(Context context, String errorId) { return super.onRecoviewableError(context, errorId); } /** * Issues a notification to inform the user that serview has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, PushAndroidActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } } } package com.example.samplegcm; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.util.Log; import com.google.android.gcm.GCMBaseIntentService; public class GCMIntentService extends GCMBaseIntentService { private static final String TAG = "GCMIntentService"; public GCMIntentService() { super(CommonUtilities.SENDER_ID); } @Oviewride protected void onRegistered(Context airg0, String registrationId) { Log.i(TAG, "Device registered: regId = " + registrationId); } @Oviewride protected void onUnregistered(Context airg0, String airg1) { Log.i(TAG, "unregistered = " + airg1); } @Oviewride protected void onMessage(Context context, Intent intent) { Log.i(TAG, "new message= "); String message = intent.getExtras().getString("message"); generateNotification(context, message); } @Oviewride protected void onError(Context airg0, String errorId) { Log.i(TAG, "Received error: " + errorId); } @Oviewride protected boolean onRecoviewableError(Context context, String errorId) { return super.onRecoviewableError(context, errorId); } /** * Issues a notification to inform the user that serview has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, PushAndroidActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } } } package com.example.samplegcm; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.util.Log; import com.google.android.gcm.GCMBaseIntentService; public class GCMIntentService extends GCMBaseIntentService { private static final String TAG = "GCMIntentService"; public GCMIntentService() { super(CommonUtilities.SENDER_ID); } @Oviewride protected void onRegistered(Context airg0, String registrationId) { Log.i(TAG, "Device registered: regId = " + registrationId); } @Oviewride protected void onUnregistered(Context airg0, String airg1) { Log.i(TAG, "unregistered = " + airg1); } @Oviewride protected void onMessage(Context context, Intent intent) { Log.i(TAG, "new message= "); String message = intent.getExtras().getString("message"); generateNotification(context, message); } @Oviewride protected void onError(Context airg0, String errorId) { Log.i(TAG, "Received error: " + errorId); } @Oviewride protected boolean onRecoviewableError(Context context, String errorId) { return super.onRecoviewableError(context, errorId); } /** * Issues a notification to inform the user that serview has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, PushAndroidActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } } vazio protegido em mensagem (Context context, intenção intenção) { package com.example.samplegcm; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.util.Log; import com.google.android.gcm.GCMBaseIntentService; public class GCMIntentService extends GCMBaseIntentService { private static final String TAG = "GCMIntentService"; public GCMIntentService() { super(CommonUtilities.SENDER_ID); } @Oviewride protected void onRegistered(Context airg0, String registrationId) { Log.i(TAG, "Device registered: regId = " + registrationId); } @Oviewride protected void onUnregistered(Context airg0, String airg1) { Log.i(TAG, "unregistered = " + airg1); } @Oviewride protected void onMessage(Context context, Intent intent) { Log.i(TAG, "new message= "); String message = intent.getExtras().getString("message"); generateNotification(context, message); } @Oviewride protected void onError(Context airg0, String errorId) { Log.i(TAG, "Received error: " + errorId); } @Oviewride protected boolean onRecoviewableError(Context context, String errorId) { return super.onRecoviewableError(context, errorId); } /** * Issues a notification to inform the user that serview has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, PushAndroidActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } } } package com.example.samplegcm; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.util.Log; import com.google.android.gcm.GCMBaseIntentService; public class GCMIntentService extends GCMBaseIntentService { private static final String TAG = "GCMIntentService"; public GCMIntentService() { super(CommonUtilities.SENDER_ID); } @Oviewride protected void onRegistered(Context airg0, String registrationId) { Log.i(TAG, "Device registered: regId = " + registrationId); } @Oviewride protected void onUnregistered(Context airg0, String airg1) { Log.i(TAG, "unregistered = " + airg1); } @Oviewride protected void onMessage(Context context, Intent intent) { Log.i(TAG, "new message= "); String message = intent.getExtras().getString("message"); generateNotification(context, message); } @Oviewride protected void onError(Context airg0, String errorId) { Log.i(TAG, "Received error: " + errorId); } @Oviewride protected boolean onRecoviewableError(Context context, String errorId) { return super.onRecoviewableError(context, errorId); } /** * Issues a notification to inform the user that serview has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, PushAndroidActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } } } package com.example.samplegcm; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.util.Log; import com.google.android.gcm.GCMBaseIntentService; public class GCMIntentService extends GCMBaseIntentService { private static final String TAG = "GCMIntentService"; public GCMIntentService() { super(CommonUtilities.SENDER_ID); } @Oviewride protected void onRegistered(Context airg0, String registrationId) { Log.i(TAG, "Device registered: regId = " + registrationId); } @Oviewride protected void onUnregistered(Context airg0, String airg1) { Log.i(TAG, "unregistered = " + airg1); } @Oviewride protected void onMessage(Context context, Intent intent) { Log.i(TAG, "new message= "); String message = intent.getExtras().getString("message"); generateNotification(context, message); } @Oviewride protected void onError(Context airg0, String errorId) { Log.i(TAG, "Received error: " + errorId); } @Oviewride protected boolean onRecoviewableError(Context context, String errorId) { return super.onRecoviewableError(context, errorId); } /** * Issues a notification to inform the user that serview has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, PushAndroidActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } } } package com.example.samplegcm; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.util.Log; import com.google.android.gcm.GCMBaseIntentService; public class GCMIntentService extends GCMBaseIntentService { private static final String TAG = "GCMIntentService"; public GCMIntentService() { super(CommonUtilities.SENDER_ID); } @Oviewride protected void onRegistered(Context airg0, String registrationId) { Log.i(TAG, "Device registered: regId = " + registrationId); } @Oviewride protected void onUnregistered(Context airg0, String airg1) { Log.i(TAG, "unregistered = " + airg1); } @Oviewride protected void onMessage(Context context, Intent intent) { Log.i(TAG, "new message= "); String message = intent.getExtras().getString("message"); generateNotification(context, message); } @Oviewride protected void onError(Context airg0, String errorId) { Log.i(TAG, "Received error: " + errorId); } @Oviewride protected boolean onRecoviewableError(Context context, String errorId) { return super.onRecoviewableError(context, errorId); } /** * Issues a notification to inform the user that serview has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, PushAndroidActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } } * / package com.example.samplegcm; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.util.Log; import com.google.android.gcm.GCMBaseIntentService; public class GCMIntentService extends GCMBaseIntentService { private static final String TAG = "GCMIntentService"; public GCMIntentService() { super(CommonUtilities.SENDER_ID); } @Oviewride protected void onRegistered(Context airg0, String registrationId) { Log.i(TAG, "Device registered: regId = " + registrationId); } @Oviewride protected void onUnregistered(Context airg0, String airg1) { Log.i(TAG, "unregistered = " + airg1); } @Oviewride protected void onMessage(Context context, Intent intent) { Log.i(TAG, "new message= "); String message = intent.getExtras().getString("message"); generateNotification(context, message); } @Oviewride protected void onError(Context airg0, String errorId) { Log.i(TAG, "Received error: " + errorId); } @Oviewride protected boolean onRecoviewableError(Context context, String errorId) { return super.onRecoviewableError(context, errorId); } /** * Issues a notification to inform the user that serview has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, PushAndroidActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } } } package com.example.samplegcm; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.util.Log; import com.google.android.gcm.GCMBaseIntentService; public class GCMIntentService extends GCMBaseIntentService { private static final String TAG = "GCMIntentService"; public GCMIntentService() { super(CommonUtilities.SENDER_ID); } @Oviewride protected void onRegistered(Context airg0, String registrationId) { Log.i(TAG, "Device registered: regId = " + registrationId); } @Oviewride protected void onUnregistered(Context airg0, String airg1) { Log.i(TAG, "unregistered = " + airg1); } @Oviewride protected void onMessage(Context context, Intent intent) { Log.i(TAG, "new message= "); String message = intent.getExtras().getString("message"); generateNotification(context, message); } @Oviewride protected void onError(Context airg0, String errorId) { Log.i(TAG, "Received error: " + errorId); } @Oviewride protected boolean onRecoviewableError(Context context, String errorId) { return super.onRecoviewableError(context, errorId); } /** * Issues a notification to inform the user that serview has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, PushAndroidActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } } 

    CommonUtilities .java

     package com.example.samplegcm; public class CommonUtilities { static final String SENDER_ID = "XXXXXXXXXXX"; // your project number from GCM } 

    PushAndroidActivity.java

      package com.example.samplegcm; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import com.google.android.gcm.GCMRegistrair; public class PushAndroidActivity extends Activity { private String TAG = "** pushAndroidActivity **"; private TextView mDisplay; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); checkNotNull(CommonUtilities.SENDER_ID, "SENDER_ID"); GCMRegistrair.checkDevice(this); GCMRegistrair.checkManifest(this); setContentView(R.layout.activity_main); mDisplay = (TextView) findViewById(R.id.display); final String regId = GCMRegistrair.getRegistrationId(this); Log.i(TAG, "registration id ===== "+regId); if (regId.equals("")) { GCMRegistrair.register(this, CommonUtilities.SENDER_ID); } else { Log.v(TAG, "Already registered"); } mDisplay.setText("Reg id is--> "+ regId); } private void checkNotNull(Object reference, String name) { if (reference == null) { throw new NullPointerException( getString(R.string.error_config, name)); } } @Oviewride protected void onPause() { super.onPause(); GCMRegistrair.unregister(this); } } importa android.widget.TextView;  package com.example.samplegcm; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import com.google.android.gcm.GCMRegistrair; public class PushAndroidActivity extends Activity { private String TAG = "** pushAndroidActivity **"; private TextView mDisplay; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); checkNotNull(CommonUtilities.SENDER_ID, "SENDER_ID"); GCMRegistrair.checkDevice(this); GCMRegistrair.checkManifest(this); setContentView(R.layout.activity_main); mDisplay = (TextView) findViewById(R.id.display); final String regId = GCMRegistrair.getRegistrationId(this); Log.i(TAG, "registration id ===== "+regId); if (regId.equals("")) { GCMRegistrair.register(this, CommonUtilities.SENDER_ID); } else { Log.v(TAG, "Already registered"); } mDisplay.setText("Reg id is--> "+ regId); } private void checkNotNull(Object reference, String name) { if (reference == null) { throw new NullPointerException( getString(R.string.error_config, name)); } } @Oviewride protected void onPause() { super.onPause(); GCMRegistrair.unregister(this); } } }  package com.example.samplegcm; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import com.google.android.gcm.GCMRegistrair; public class PushAndroidActivity extends Activity { private String TAG = "** pushAndroidActivity **"; private TextView mDisplay; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); checkNotNull(CommonUtilities.SENDER_ID, "SENDER_ID"); GCMRegistrair.checkDevice(this); GCMRegistrair.checkManifest(this); setContentView(R.layout.activity_main); mDisplay = (TextView) findViewById(R.id.display); final String regId = GCMRegistrair.getRegistrationId(this); Log.i(TAG, "registration id ===== "+regId); if (regId.equals("")) { GCMRegistrair.register(this, CommonUtilities.SENDER_ID); } else { Log.v(TAG, "Already registered"); } mDisplay.setText("Reg id is--> "+ regId); } private void checkNotNull(Object reference, String name) { if (reference == null) { throw new NullPointerException( getString(R.string.error_config, name)); } } @Oviewride protected void onPause() { super.onPause(); GCMRegistrair.unregister(this); } } }  package com.example.samplegcm; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import com.google.android.gcm.GCMRegistrair; public class PushAndroidActivity extends Activity { private String TAG = "** pushAndroidActivity **"; private TextView mDisplay; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); checkNotNull(CommonUtilities.SENDER_ID, "SENDER_ID"); GCMRegistrair.checkDevice(this); GCMRegistrair.checkManifest(this); setContentView(R.layout.activity_main); mDisplay = (TextView) findViewById(R.id.display); final String regId = GCMRegistrair.getRegistrationId(this); Log.i(TAG, "registration id ===== "+regId); if (regId.equals("")) { GCMRegistrair.register(this, CommonUtilities.SENDER_ID); } else { Log.v(TAG, "Already registered"); } mDisplay.setText("Reg id is--> "+ regId); } private void checkNotNull(Object reference, String name) { if (reference == null) { throw new NullPointerException( getString(R.string.error_config, name)); } } @Oviewride protected void onPause() { super.onPause(); GCMRegistrair.unregister(this); } } }  package com.example.samplegcm; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import com.google.android.gcm.GCMRegistrair; public class PushAndroidActivity extends Activity { private String TAG = "** pushAndroidActivity **"; private TextView mDisplay; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); checkNotNull(CommonUtilities.SENDER_ID, "SENDER_ID"); GCMRegistrair.checkDevice(this); GCMRegistrair.checkManifest(this); setContentView(R.layout.activity_main); mDisplay = (TextView) findViewById(R.id.display); final String regId = GCMRegistrair.getRegistrationId(this); Log.i(TAG, "registration id ===== "+regId); if (regId.equals("")) { GCMRegistrair.register(this, CommonUtilities.SENDER_ID); } else { Log.v(TAG, "Already registered"); } mDisplay.setText("Reg id is--> "+ regId); } private void checkNotNull(Object reference, String name) { if (reference == null) { throw new NullPointerException( getString(R.string.error_config, name)); } } @Oviewride protected void onPause() { super.onPause(); GCMRegistrair.unregister(this); } } }  package com.example.samplegcm; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import com.google.android.gcm.GCMRegistrair; public class PushAndroidActivity extends Activity { private String TAG = "** pushAndroidActivity **"; private TextView mDisplay; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); checkNotNull(CommonUtilities.SENDER_ID, "SENDER_ID"); GCMRegistrair.checkDevice(this); GCMRegistrair.checkManifest(this); setContentView(R.layout.activity_main); mDisplay = (TextView) findViewById(R.id.display); final String regId = GCMRegistrair.getRegistrationId(this); Log.i(TAG, "registration id ===== "+regId); if (regId.equals("")) { GCMRegistrair.register(this, CommonUtilities.SENDER_ID); } else { Log.v(TAG, "Already registered"); } mDisplay.setText("Reg id is--> "+ regId); } private void checkNotNull(Object reference, String name) { if (reference == null) { throw new NullPointerException( getString(R.string.error_config, name)); } } @Oviewride protected void onPause() { super.onPause(); GCMRegistrair.unregister(this); } } }  package com.example.samplegcm; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import com.google.android.gcm.GCMRegistrair; public class PushAndroidActivity extends Activity { private String TAG = "** pushAndroidActivity **"; private TextView mDisplay; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); checkNotNull(CommonUtilities.SENDER_ID, "SENDER_ID"); GCMRegistrair.checkDevice(this); GCMRegistrair.checkManifest(this); setContentView(R.layout.activity_main); mDisplay = (TextView) findViewById(R.id.display); final String regId = GCMRegistrair.getRegistrationId(this); Log.i(TAG, "registration id ===== "+regId); if (regId.equals("")) { GCMRegistrair.register(this, CommonUtilities.SENDER_ID); } else { Log.v(TAG, "Already registered"); } mDisplay.setText("Reg id is--> "+ regId); } private void checkNotNull(Object reference, String name) { if (reference == null) { throw new NullPointerException( getString(R.string.error_config, name)); } } @Oviewride protected void onPause() { super.onPause(); GCMRegistrair.unregister(this); } } 

    Manifestfile

      <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.samplegcm" android:viewsionCode="1" android:viewsionName="1.0" > <uses-sdk android:minSdkVersion="8" android:tairgetSdkVersion="17" /> <permission android:name="com.example.samplegcm.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.example.samplegcm.permission.C2D_MESSAGE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.samplegcm.PushAndroidActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiview android:name="com.google.android.gcm.GCMBroadcastReceiview" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.example.samplegcm" /> </intent-filter> </receiview> <service android:name=".GCMIntentService" /> </application> </manifest> 

    Veja este link. Este link fornece o tutorial completo paira mensagens em nuvem.

    http://www.androidhub4you.com/2013/04/google-cloud-messaging-example-in.html

    link útil paira o exemplo do android gcm … Você não precisa criair files do server … você só precisa do ID do projeto, a key do Google api …

    http://www.androidbegin.com/tutorial/android-google-cloud-messaging-gcm-tutorial/#more-556

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.