Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BurningDroid/547c9cf918ace81b51fd1e810bd7b0b9 to your computer and use it in GitHub Desktop.
Save BurningDroid/547c9cf918ace81b51fd1e810bd7b0b9 to your computer and use it in GitHub Desktop.
public class FCMService extends FirebaseMessagingService {
public FCMService() {
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
if (remoteMessage.getData().size() > 0) {
sendNotification(remoteMessage.getData());
}
}
private void sendNotification(Map<String, String> messageMap) {
String recruitId = messageMap.get("recruitId");
String body = messageMap.get("body");
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_user_add)
.setContentTitle("FCM Message")
.setContentText(body)
.setAutoCancel(true)
.setSound(defaultSoundUri)
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment