Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在API 26中添加音乐播放器通知_Java_Android_Android Studio_Notifications_Android 8.0 Oreo - Fatal编程技术网

Java 如何在API 26中添加音乐播放器通知

Java 如何在API 26中添加音乐播放器通知,java,android,android-studio,notifications,android-8.0-oreo,Java,Android,Android Studio,Notifications,Android 8.0 Oreo,我已经成功地显示了通知,但问题是它没有按预期工作。问题是- 1.我不知道如何把通知放在首位 2.当我滑动通知时,它会显示snooze图标,但不会显示在任何其他音乐应用程序中 这是我的密码 `if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { RemoteViews expandedView = new RemoteViews(getContext().getPackageName(), R.la

我已经成功地显示了通知,但问题是它没有按预期工作。问题是- 1.我不知道如何把通知放在首位 2.当我滑动通知时,它会显示snooze图标,但不会显示在任何其他音乐应用程序中

这是我的密码

`if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    RemoteViews expandedView = new RemoteViews(getContext().getPackageName(), R.layout.custom_push);
                    CharSequence name = "Music Player";
                    String description = "Play music in background";
                    int importance = NotificationManager.IMPORTANCE_LOW;
                    NotificationChannel channel = new NotificationChannel("Music Player", name, importance);
                    channel.setDescription(description);
                    channel.setShowBadge(false);
                    // Register the channel with the system; you can't change the importance
                    // or other notification behaviors after this
                    NotificationCompat.Builder nc = new NotificationCompat.Builder(getContext(),"Music Player");
                    Intent notifyIntent = new Intent(getContext(), now_playing.class);

                    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    PendingIntent pendingIntent = PendingIntent.getActivity(getContext(),0,notifyIntent,PendingIntent.FLAG_UPDATE_CURRENT);
                    nc.setContentIntent(pendingIntent);
                    nc.setCustomBigContentView(expandedView);
                    nc.setSmallIcon(R.drawable.notification_icon);
                    nc.setAutoCancel(false);
                    nc.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
                    nc.setOngoing(true);
                    NotificationManager notificationManager = getActivity().getSystemService(NotificationManager.class);
                    notificationManager.createNotificationChannel(channel);
                    notificationManager.notify(1, nc.build());
                }`
我还注意到其他音乐播放器的设置中没有任何通知频道。如果有人告诉我如何正确实施通知,那就太好了。 谢谢

根据

1) 只能使用NotificationManager设置通知的优先级。重要性\u高
2) 需要知道其他音乐应用程序频道的标识符
CHANNEL\u ID
,也许这篇文章可以帮助您:

在创建通知频道时设置通知重要性高NotificationManger.importance\u高

  NotificationChannel channel = new NotificationChannel(channelId, ChannelName, NotificationManager.IMPORTANCE_HIGH);

使用重要性_HIGH还可以播放通知声音,振动设备并像平视显示器一样显示通知,就像文本消息一样。set channel.setSound(null,null);如果您不想为Notification设置声音,则仍然无法工作。每当有新的通知出现,而其他音乐播放器总是在顶部,而新的通知出现在它们下面时,它就会下降。是否已删除该应用程序并重新安装?尝试从通知手动设置重要性。感谢Jhoan链接,但不幸的是,它没有解决问题。我也有同样的问题。当其他正常通知出现时,我的前台通知也会下降。你解决问题了吗?没有,我的朋友。我开始为android开发游戏。