Skip to content

Instantly share code, notes, and snippets.

@nazmulidris
Created January 8, 2018 16:11
Show Gist options
  • Select an option

  • Save nazmulidris/ecf2fb74b62449ee0bdf2df2d8ff9684 to your computer and use it in GitHub Desktop.

Select an option

Save nazmulidris/ecf2fb74b62449ee0bdf2df2d8ff9684 to your computer and use it in GitHub Desktop.
@TargetApi(25)
public static class PreO {
public static void createNotification(Service context) {
// Create Pending Intents.
PendingIntent piLaunchMainActivity =
getLaunchActivityPI(context);
PendingIntent piStopService = getStopServicePI(context);
// Action to stop the service.
NotificationCompat.Action stopAction =
new NotificationCompat.Action.Builder(
STOP_ACTION_ICON,
getNotificationStopActionText(context),
piStopService)
.build();
// Create a notification.
Notification mNotification =
new NotificationCompat.Builder(context)
.setContentTitle(getNotificationTitle(context))
.setContentText(getNotificationContent(context))
.setSmallIcon(SMALL_ICON)
.setContentIntent(piLaunchMainActivity)
.addAction(stopAction)
.setStyle(new NotificationCompat.BigTextStyle())
.build();
context.startForeground(
ONGOING_NOTIFICATION_ID, mNotification);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment