Android8.1_Notification_个人用例_SDK27_渠道

18/3/13$

        public void sendNotification() {
            Intent resultIntent = new Intent(this, MainActivity.class);
            PendingIntent resultPendingIntent = PendingIntent.getActivity(
                    this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_launcher_background)
                        .setContentTitle("Notification")
                        .setContentText("test")
                        .setPriority(Notification.PRIORITY_MAX)
                        //.setOngoing(true)
                        //.setDefaults(Notification.DEFAULT_VIBRATE)
                        .setVisibility(Notification.VISIBILITY_PUBLIC)
                        .setContentIntent(resultPendingIntent);
                        //.setWhen(System.currentTimeMillis() + System.currentTimeMillis());
                Notification notification = builder.build();


                notification.flags |= Notification.FLAG_NO_CLEAR;
                //notification.flags |= Notification.FLAG_ONGOING_EVENT;
                notification.flags |= Notification.FLAG_AUTO_CANCEL;
//                Runnable runnable = new Runnable() {
//                    @Override
//                    public void run() {
//                        mnotifyManager.notify(1, notification);
//                    }
//                };
//                handler.postDelayed(runnable,2000);
//            if (Build.VERSION.SDK_INT >= 26) {
//                intent = new Intent(MainActivity.this, SecondActivity.class);
//                PendingIntent pintent = PendingIntent.getActivity(this, 0, intent, 0);
                String id = "channel_1";
                String description = "渠道1";
                int importance = NotificationManager.IMPORTANCE_LOW;
                NotificationChannel mChannel = new NotificationChannel(id, description, importance);
                  mChannel.setDescription(description);
                  mChannel.enableLights(true);
                  mChannel.setLightColor(Color.RED);
                  mChannel.setImportance(IMPORTANCE_MAX);
                  //mChannel.enableVibration(true);
//                //  mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
            notificationManager = mnotifyManager;
            mNotificationManager = notificationManager;
            mNotificationManager.createNotificationChannel(mChannel);
            notification = new Notification.Builder(MainActivity.this, id).setContentTitle("Title")
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                    .setContentTitle("您有一条新通知")
                    .setContentText("这是一条xx的消息")
                    .setAutoCancel(true)
//                        .setContentIntent(pintent)
                    .build();
                mNotificationManager.notify(1, notification);
//            }else{
//                sendNotification_24();
//            }
            }

8.1新通知构成用例

渠道构造体

通知构造体


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值