Skip to content

Instantly share code, notes, and snippets.

@karthiks
Created August 24, 2017 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthiks/9cf6844da01aee0fd4f834b8579ad5c7 to your computer and use it in GitHub Desktop.
Save karthiks/9cf6844da01aee0fd4f834b8579ad5c7 to your computer and use it in GitHub Desktop.
Create Notification object using Builder
public class NotificationUtils extends ContextWrapper {
public static final String ANDROID_CHANNEL_ID = "com.androidstuff.tutsplustalerts.ANDROID";
public static final String IOS_CHANNEL_ID = "com.androidstuff.tutsplustalerts.IOS";
public static final String ANDROID_CHANNEL_NAME = "ANDROID CHANNEL";
public static final String IOS_CHANNEL_NAME = "IOS CHANNEL";
private NotificationManager notificationManager;
public NotificationUtils(Context base) {
super(base);
createChannels();
}
//..
public Notification getAndroidChannelNotification(String title, String body) {
return new Notification.Builder(getApplicationContext(), ANDROID_CHANNEL_ID)
.setContentTitle(title)
.setContentText(body)
.setSmallIcon(android.R.drawable.stat_notify_more)
.setAutoCancel(true)
.build();
}
public Notification getIosChannelNotification(String title, String body) {
return new Notification.Builder(getApplicationContext(), IOS_CHANNEL_ID)
.setContentTitle(title)
.setContentText(body)
.setSmallIcon(android.R.drawable.stat_notify_more)
.setAutoCancel(true)
.build();
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment