Skip to content

Instantly share code, notes, and snippets.

@hiranya911
Created February 18, 2018 20:49
Show Gist options
  • Save hiranya911/f3c516acac299eb94ef74668fa1ef496 to your computer and use it in GitHub Desktop.
Save hiranya911/f3c516acac299eb94ef74668fa1ef496 to your computer and use it in GitHub Desktop.
private static final String ANDROID_NEWS_ICON_RESOURCE = "news_alert_icon";
private static final int APNS_NEWS_BADGE_RESOURCE = 42;
private static final String WEBPUSH_NEWS_ICON_URL = "https://auto.news.url/alert.png";
public String sendAutoNewsAlert(String title, String body) throws Exception {
Message message = Message.builder()
.setNotification(new Notification(title, body))
.setAndroidConfig(AndroidConfig.builder()
.setNotification(AndroidNotification.builder()
.setIcon(ANDROID_NEWS_ICON_RESOURCE)
.build())
.build())
.setApnsConfig(ApnsConfig.builder()
.setAps(Aps.builder()
.setBadge(APNS_NEWS_BADGE_RESOURCE)
.build())
.build())
.setWebpushConfig(WebpushConfig.builder()
.setNotification(new WebpushNotification(null, null, WEBPUSH_NEWS_ICON_URL))
.build())
.setTopic("auto-news")
.build();
return FirebaseMessaging.getInstance().sendAsync(message).get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment