private void sendNotification(NearbyPlayer nearbyPlayer) { Intent intent = new Intent(context, actionToNotificate); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pIntent = PendingIntent.getActivity(context, 2, intent, PendingIntent.FLAG_UPDATE_CURRENT); Builder builder = new Builder(context); switch (nearbyPlayer.getFaction()) { case blue: builder.setSmallIcon(R.drawable.blue_small); break; case green: builder.setSmallIcon(R.drawable.green_small); break; } builder.setContentIntent(pIntent); builder.setContentTitle(nearbyPlayer.getName()); builder.setContentInfo( nearbyPlayer.getHumanReadableDistance() + " " + nearbyPlayer.getDirection() + " " + nearbyPlayer.getHumanReadableTime() + " ago on " + nearbyPlayer.getLocation()); Notification noti = builder.build(); noti.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, noti); this.lastNotification = nearbyPlayer; }