In case you are using GcmListenerService
public class MyGCMService extends GcmListenerService {
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
if(data.containsKey("type"))
{
String type = data.getString("type");
if(type.equalsIgnoreCase("qr_update"))
{
SharedPrefUtil.setSharedPref(getApplicationContext(), "qr", "");
}
}
else
{
sendNotification(message);
}
}
private void sendNotification(String message)
{
initiateNotification(message);
}
private void initiateNotification(String message)
{
Intent intent = new Intent(this, Splash.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(getResources().getString(R.string.app_name))
//.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 , notificationBuilder.build());
}
}
Even though I will recommend you to use FCM as GCM is depricated