- Create a notification
Create a Notification.Builder:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
Then issue the notification:
// Sets an ID for the notification
int mNotificationId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());
- Listen to notification (using GCM permissions)
Add permissions into AndroidManifest.xml
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>
public class GCMBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = GCMBroadcastReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
if ("com.google.android.c2dm.intent.REGISTRATION".equals(intent.getAction())) {
// Register Localytics (this will call Localytics.handleRegistration(intent))
new PushReceiver().onReceive(context, intent);
} else if ("com.google.android.c2dm.intent.RECEIVE".equals(intent.getAction())) {
// DO SOMETHING
}
}
}