...
Code Block | ||
---|---|---|
| ||
public class YourControlService extends PopControlService { @Override protected Notification buildForegroundNotification(@NonNull String unitId, @NonNull PopNotificationConfig popNotificationConfig) { // Pop을 표시하는 PendingIntent (원형 아이콘ㅇ) PendingIntent popPendingIntent = getPopPendingIntent(unitId, this); // 필요에 따라 notificationChannel을 등록합니다. NotificationCompat.Builder builder; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { createNotificationChannelIfNeeded(); builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID); } else { builder = new NotificationCompat.Builder(this); } // Pop Service Notification 에 사용할 View 를 등록합니다. RemoteViews remoteView = new RemoteViews(getPackageName(), R.layout.view_custom_notification); builder.setSmallIcon(popNotificationConfig.getSmallIconResId()) .setContent(remoteView) .setContentIntent(popPendingIntent) .setPriority(PRIORITY_LOW) .setShowWhen(false); if (popNotificationConfig.getColor() == null) { builder.setColor(popNotificationConfig.getColor()); } return builder.build(); } @TargetApi(Build.VERSION_CODES.O) privateprotected void createNotificationChannelIfNeeded() { final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID) == null) { final NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW); channel.setShowBadge(false); notificationManager.createNotificationChannel(channel); } } } |
...