Last active
July 11, 2020 07:53
-
-
Save MrCrambo/82bfb3f11b918882ab1425371edce6eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class NotificationService extends Service { | |
| private static final int ID_SERVICE = 101; | |
| @Nullable @Override public IBinder onBind(Intent intent) { | |
| return null; | |
| } | |
| @Override public void onCreate() { | |
| super.onCreate(); | |
| NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); | |
| String channelId = createNotificationChannel(notificationManager); | |
| NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId); | |
| Notification notification = notificationBuilder.setOngoing(true) | |
| .setContentTitle("Navigine Service Example") | |
| .setCategory(NotificationCompat.CATEGORY_SERVICE) | |
| .build(); | |
| startForeground(ID_SERVICE, notification); | |
| } | |
| @Override public int onStartCommand(Intent intent, int flags, int startId) { | |
| super.onStartCommand(intent, flags, startId); | |
| return START_REDELIVER_INTENT; | |
| } | |
| private String createNotificationChannel(NotificationManager notificationManager){ | |
| String channelId = "NAVIGINE_SERVICE_CHANNEL_ID_EXAMPLE"; | |
| String channelName = "NAVIGINE CHANNEL NAME EXAMPLE"; | |
| NotificationChannel channel = new NotificationChannel(channelId, | |
| channelName, | |
| NotificationManager.IMPORTANCE_HIGH); | |
| channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); // will be shown in lock screen | |
| notificationManager.createNotificationChannel(channel); | |
| return channelId; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment