奥利奥中闹钟缺少功能的通知



我一直在通过 youtube 构建闹钟 作者:Anna Xu

她最终将她的代码保留在 If 语句中,它似乎可以单击并很好地启动她的应用程序。我根据在 Pixel XL 上搜索奥利奥的修复程序进行了修改。 这是我到目前为止所拥有的:

// 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();

最新更新