Mp3 çalar uygulaması üzerinde çalışıyorum. Playerin arkaplanda çalışabilmesi için servis içerisine ekledim orada çalışıyor. Android Oreo sonrası için servis çalışırken bildirim göstermek gerekiyor ve bildirim olduğu zamanda led yanıp sönüyor. İstediğim, bildirim ışığını pasif hale getirmek. Müzik çalarken bildirim ışığının sürekli yanıp sönmesi kullanıcı açısından iyi olmaz. Servis sınıfının kodları aşağıdadır.

public class MusicPlayService extends Service {
public static boolean firstStartService = false;
public static int RESUME_PATH;
public static MediaPlayer player;

@Override
public void onCreate() {
firstStartService = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startMyOwnForeground(); } else {}
player = new MediaPlayer();

super.onCreate();
}

/*Create custom notify*/
private void startMyOwnForeground() {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

int notificationId = 45;
String channelId = "Music Play";
String channelName = "Music Play ";
int importance = NotificationManager.IMPORTANCE_HIGH;


RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notify);
contentView.setImageViewResource(R.id.image, R.mipmap.ic_launcher_round);
contentView.setTextViewText(R.id.title, DataModel.songArtist.get(RESUME_PATH));
contentView.setTextViewText(R.id.notifyMessage, DataModel.songName.get(RESUME_PATH));

Intent switchIntent = new Intent(this, StopServiceReceiver.class);
PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0,
switchIntent, 0);

contentView.setOnClickPendingIntent(R.id.btnCloseNotif,
pendingSwitchIntent);

Intent i = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addNextIntent(i);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(
channelId, channelName, importance);
mChannel.setLightColor(Color.CYAN);
mChannel.enableLights(true);
mChannel.setVibrationPattern(null);
mChannel.setSound(null, null);
notificationManager.createNotificationChannel(mChannel);
}


NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId);
Notification notification = notificationBuilder.setOngoing(true)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setAutoCancel(true)
.setCustomContentView(contentView)
.setVibrate(null)
.setSound(null)
.setDefaults(Notification.DEFAULT_LIGHTS)
.setContentIntent(resultPendingIntent)
.build();


startForeground(notificationId, notification);

}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

startMyOwnForeground();
try {
startSong(DataModel.songPathName.get(RESUME_PATH) + MyConstants.FILE_TYPE);
} catch (Exception e) {
startSong(SongAdapter.songPath);
}

tvSongArtistPlayer.setText(DataModel.songArtist.get(RESUME_PATH));
tvTitleSongPlayer.setText(DataModel.songName.get(RESUME_PATH));
SetPlayerImage(RESUME_PATH);

player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
if (RESUME_PATH < DataModel.songPathName.size() - 1) {
RESUME_PATH++;
// stopSelf();
Intent intesnt = new Intent(getApplicationContext(), MusicPlayService.class);
stopService(intesnt);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ContextCompat.startForegroundService(getApplicationContext(), intesnt);
} else {
startService(intesnt);
}
}
}
});
return START_NOT_STICKY;
}

/*Set player image Bitmap*/
private void SetPlayerImage(int i) {
try {
InputStream is = getAssets().open("image/" + DataModel.songImagePathName.get(i));
Bitmap bitmap = BitmapFactory.decodeStream(is);
img_circle_player.setImageBitmap(bitmap);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}


private void startSong(String filename) {

AssetFileDescriptor afd = null;
try {
afd = getAssets().openFd("song/" + filename);
} catch (IOException e) {
e.printStackTrace();
}
player = new MediaPlayer();
try {
player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
player.prepare();
} catch (IOException e) {
e.printStackTrace();
}
// if (duration>0){
// player.seekTo(duration);}
player.start();

}

@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the ser
return null;
}

}