Oreo 中缺少闹钟功能的通知

Notifications for an alarm clock missing functionality in Oreo

我一直在通过 Anna Xuyoutube tutorial

制作一个闹钟

她最终将她的代码保存在 If 语句中,它似乎可以正常点击并调出她的应用程序。我根据在 Pixel XL 上搜索 Oreo 修复程序进行了修改。这是我目前所拥有的:

// notification parameters
        int notifyID = 1;
        String CHANNEL_ID = "my channel_01";
        CharSequence name = "Hello";
        int importance = NotificationManager.IMPORTANCE_HIGH;
        NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
        // set up the notification service
        NotificationManager notify_manager = (NotificationManager)
                getSystemService(Context.NOTIFICATION_SERVICE);
        notify_manager.createNotificationChannel(mChannel);

        Notification notification_popup = new Notification.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher_foreground)
                .setContentTitle("An alarm is going off!")
                .setContentText("Click me!")
                .setChannelId(CHANNEL_ID).build();
        // set up notification start command
        notify_manager.notify(0, notification_popup);

这会在闹钟响起时弹出通知,但点击不会弹出应用程序,实际上我认为您根本无法点击它,只能将其滑开。我只想能够单击通知将应用程序带到前台。我是 Java 和 Android Studio 的超级新手,现在奥利奥系统闹钟不可信,这一切都是出于必要。任何帮助都会很棒。

 //Create pendingIntent to open your particular activity     
  Intent notificationIntent = new Intent(context, YourActivity.class);

            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);

            PendingIntent intent = PendingIntent.getActivity(context, 0,
                    notificationIntent, 0);
           //Then edit here 

           Notification notification_popup = new Notification.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher_foreground)
                    .setContentTitle("An alarm is going off!")
                    .setContentText("Click me!")
                    .setContentIntent(notificationIntent )
                    .setChannelId(CHANNEL_ID).build();