Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.foreground);
NotificationCompat.Builder builder;
if (Build.VERSION.SDK_INT >= 26) {
String CHANNEL_ID = "TEST_CHANNEL";
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "TEST Service Channel", NotificationManager.IMPORTANCE_DEFAULT);
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
builder = new NotificationCompat.Builder(this, CHANNEL_ID);
} else {
builder = new NotificationCompat.Builder(this);
}
builder.setSmallIcon(R.mipmap.ic_launcher)
.setContent(remoteViews)
.setContentIntent(pendingIntent);
startForeground(1, builder.build());