我的代码中的频道名称和频道说明是哪一个?

我正在为媒体播放器创建通知频道,并找到了推荐的方法,但是我不知道哪个是channel_name,哪个是channel_description。其次,我无法在通知中看到我的控件(上一个,播放和下一个)旁边的图标。我只看到这些标签,单击时它们什么也没做。

public class NotifyApp extends Application {

    // Registering notification channel

    public static final String CHANNEL_ID = "playerServiceChannel";

    @Override
    public void onCreate() {
        super.onCreate();

        createNotificationChannel();
    }

    private void createNotificationChannel() {

        // Creating the NotificationChannel, but only on API 26+ because
        // the NotificationChannel class is new and not in the support library

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            CharSequence name = getString(R.string./***channel_name*/);
            String description = getString(R.string./***channel_description*/);
            int importance = NotificationManager.IMPORTANCE_DEFAULT;
            NotificationChannel serviceChannel = new NotificationChannel(
                    CHANNEL_ID,
                    "Player Service Channel",
                    NotificationManager.IMPORTANCE_DEFAULT
            );

            NotificationManager manager = getSystemService(NotificationManager.class);
            manager.createNotificationChannel(serviceChannel);
        }
    }
}

这是我的Constants.java类中的代码:

public class Constants {
    public interface ACTION {
        public static String MAIN_ACTION = "net.groupkse.indupendo.action.main";
        public static String PREV_ACTION = "net.groupkse.indupendo.action.prev";
        public static String PLAY_ACTION = "net.groupkse.indupendo.action.prev";
        public static String NEXT_ACTION = "net.groupkse.indupendo.action.next";
        public static String STARTFOREGROUND_ACTION = "net.groupkse.indupendo.action.startforeground";
        public static String STOPFOREGROUND_ACTION = "net.groupkse.indupendo.action.stopforeground";
    }

    public interface NOTIFICATION_ID {
        public static int FOREGROUND_SERVICE = 101;
    }
}

这是我的PlayerService.java类中的代码:

public class PlayerService extends Service {

    // Creating new MediaPlayer

    MediaPlayer mediaPlayer = new MediaPlayer();
    private IBinder mBinder = new MyBinder ();

    public class MyBinder extends Binder {
        PlayerService getService () {
            return PlayerService.this;
        }
    }

    public PlayerService() {

    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (intent.getStringExtra("url") != null)
            playStream(intent.getStringExtra("url"));

        if (intent.getAction().equals(Constants.ACTION.STARTFOREGROUND_ACTION)) {
            Log.i("info", "Start foreground service!");
            showNotification();

        } else if (intent.getAction().equals(Constants.ACTION.PREV_ACTION)) {
            Log.i("info", "Prev pressed.");

        } else if (intent.getAction().equals(Constants.ACTION.PLAY_ACTION)) {
            Log.i("info", "Play pressed.");
            togglePlayer();

        } else if (intent.getAction().equals(Constants.ACTION.NEXT_ACTION)) {
            Log.i("info", "Next pressed.");

        } else if (intent.getAction().equals(Constants.ACTION.STOPFOREGROUND_ACTION)) {
            Log.i("info", "Stop foreground received.");
            stopForeground(true);
            stopSelf();
        }

        return START_REDELIVER_INTENT;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    private void showNotification () {
        Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.setAction(Constants.ACTION.MAIN_ACTION);
        //notificationIntent.setFlags((Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

        Intent previousIntent = new Intent(this, PlayerService.class);
        previousIntent.setAction(Constants.ACTION.PREV_ACTION);
        PendingIntent ppreviousIntent = PendingIntent.getActivity(this, 0, previousIntent, 0);

        Intent playIntent = new Intent(this, PlayerService.class);
        playIntent.setAction(Constants.ACTION.PLAY_ACTION);
        PendingIntent pplayIntent = PendingIntent.getActivity(this, 0, playIntent, 0);

        Intent nextIntent = new Intent(this, PlayerService.class);
        nextIntent.setAction(Constants.ACTION.NEXT_ACTION);
        PendingIntent pnextIntent = PendingIntent.getActivity(this, 0, nextIntent, 0);

        Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_kwacha_coin);

        int playPauseButtonId = android.R.drawable.ic_media_play;

        if (mediaPlayer != null && mediaPlayer.isPlaying())
            playPauseButtonId = android.R.drawable.ic_media_pause;

        String labelId = "Play";
        if (mediaPlayer != null && mediaPlayer.isPlaying())
            labelId = "Pause";

        Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
                .setContentTitle("Music Player")
                .setTicker("Playing music")
                .setContentText("My song")
                .setSmallIcon(R.drawable.ic_kwacha_coin)
                .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false))
                .setContentIntent(pendingIntent)
                .setOngoing(true)
                .addAction(android.R.drawable.ic_media_previous, "Previous", ppreviousIntent)
                .addAction(playPauseButtonId, labelId, pplayIntent)
                .addAction(android.R.drawable.ic_media_next, "Next", pnextIntent)
                .build();
        startForeground(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE, notification);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return mBinder;
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public void playStream (String url) {
        if (mediaPlayer != null) {
            try {
                mediaPlayer.stop();
            } catch (Exception e) {

            }

            // Releasing everything from the mediaPlayer

            mediaPlayer = null;
        }

        // Creating new Media Player

        mediaPlayer = new MediaPlayer();
        //mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setAudioAttributes(
                new AudioAttributes.Builder()
                        .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                        .build()
        );

        // Try & Catch errors

        try {
            mediaPlayer.setDataSource(url);
            mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    playPlayer();
                }
            });
            mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mp) {
                    flipPlayPauseButton(false);
                }
            });
            mediaPlayer.prepareAsync();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void pausePlayer () {
        try {
            mediaPlayer.pause();
            flipPlayPauseButton(false);
            showNotification();
        } catch (Exception e) {
            Log.d("EXCEPTION", "Failed to pause Media Player");
        }
    }

    public void playPlayer () {
        try {
            mediaPlayer.start();
            flipPlayPauseButton(true);
            showNotification();
        } catch (Exception e) {
            Log.d("EXCEPTION", "Failed to start Media Player");
        }
    }

    public void flipPlayPauseButton (boolean isPlaying) {

        // Code to communicate with main thread
        Intent intent = new Intent("changePlayButton");

        //  Add data to the above intent
        intent.putExtra("isPlaying", isPlaying);
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
    }

    public void togglePlayer () {
        try {
            if (mediaPlayer.isPlaying())
                pausePlayer();
            else
                playPlayer();
        } catch (Exception e) {
            Log.d("Exception", "Failed to toggle Media Player");
        }
    }
}