首页 > 解决方案 > 每日重复通知,已弃用 N̶o̶t̶i̶f̶i̶c̶a̶t̶i̶o̶n̶C̶o̶m̶p̶a̶t̶.̶B̶u̶i̶l̶d̶e̶r̶

问题描述

我正在搜索用于创建通知的最新代码,因为我拥有的代码不起作用并且它说该代码已被弃用。

我的代码实际上类似于这个问题的答案,除了我的看起来像这样......

在我的清单上它变成红色,我知道为什么;

在此处输入图像描述

但是我也有这个代码(它可以工作),但我想不出如何让它在指定的时间每天重复;

    Intent i = new Intent(this,MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), i, 0);

    Bitmap bitmapI = BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher_round);

    Notification notification = new Notification.Builder(this)
            .setContentTitle("Sample title")
            .setContentText("Sample content")
            .setSmallIcon(R.mipmap.ic_launcher_round)
            .setLargeIcon(bitmapI)
            .setContentIntent(pendingIntent)
            .build();

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notification.flags |=  Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);`

如果你们想看看我的实际代码,就说,我会编辑我的问题。

标签: androidandroid-serviceandroid-alarmsandroid-broadcastreceiver

解决方案


推荐阅读