startForeground中id设置为0后,startForeground无效

我startForeground的id设置为0后,一开始是可以探出通知的,但是后来就没反应了。如果把0改成其他数字,startForeground是好用的,有人知道是什么原因吗?
                createNotificationChanel("alarm");
                Calendar calendar=Calendar.getInstance();
                NotificationManager notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                notificationManager.cancelAll();
                Notification notification=new NotificationCompat.Builder(this,"alarm")
                        .setSmallIcon(R.mipmap.ic_launcher_round)
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher_round))
                        .setContentTitle("闹钟")
                        .setContentText("7:00")
                        .setSound(Uri.parse("android.resource://"+getApplicationContext().getPackageName()+
                                "/"+R.raw.bell))
                        .setPriority(NotificationCompat.PRIORITY_MAX)
                        .setWhen(calendar.getTimeInMillis())
                        .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                        .build();
                LogInfo.d("****startForeground ");
                startForeground(0,notification);
createNotificationChanel的定义如下
    private void createNotificationChanel( String chanelID){
        LogInfo.d("createNotificationChanel start");
        // Create 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){
            String channelName="闹钟";
            String description="允许闹钟响应";
            int importance= NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel channel=new NotificationChannel(chanelID,channelName,importance);
            channel.setDescription(description);
            NotificationManager notificationManager=getSystemService(NotificationManager.class);
            notificationManager.createNotificationChannel(channel);
        }
    }

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值