android开发通知常用设置方法

简单记录 通知上的设置方法,没有示例

 //进度 通知
            notificationManager = (NotificationManager)
                    context.getSystemService(Context.NOTIFICATION_SERVICE);
            builder = new NotificationCompat.Builder(context);
            builder.setContentTitle("新版本")//显示的标题
                    .setContentText("正在下载...")//显示的详细内容
                    .setSmallIcon(R.mipmap.ic_launcher);
            //提示文字
            builder.setTicker("您有新消息!");
            //点击取消,优先级
            builder.setAutoCancel(true).
                    setPriority(NotificationCompat.PRIORITY_DEFAULT);

            builder.setDefaults(Notification.DEFAULT_ALL);
            // 关联PendingIntent,点击跳转的页面
            //PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            // new Intent(this, MainActivity.class), 0);
            //builder.setContentIntent();
            //指定视图Notification 正常状态下的视图
            // builder.build().contentView=contentView;
            //展开时的视图
            //builder.build().bigContentView = expandView;
              /*提示方式
            DEFAULT_ALL:铃声、闪光、震动均系统默认。
            DEFAULT_SOUND:系统默认铃声。
            DEFAULT_VIBRATE:系统默认震动。
            DEFAULT_LIGHTS:系统默认闪光。
            其他方式:
            setSound(Uri sound):设定一个铃声,用于在通知的时候响应。
            传递一个Uri的参数,格式为“file:///mnt/sdcard/Xxx.mp3”。
            setLights(int argb, int onMs, int offMs):设定前置LED灯的闪烁速率,
            持续毫秒数,停顿毫秒数。
            setVibrate(long[] pattern):设定震动的模式,以一个long数组保存毫秒级间隔的震动。
            */
            /*
            setStyle()传递一个NotificationCompat.Style对象,它是一个抽象类,
            Android为我们提供了三个实现类,用于显示不同的场景。分别是:
            NotificationCompat.BigPictureStyle, 在细节部分显示一个256dp高度的位图。
            NotificationCompat.BigTextStyle,在细节部分显示一个大的文本块。
            NotificationCompat.InboxStyle,在细节部分显示一段行文本。*/
            //builder.setWhen();//设置通知的时间,默认当前时间

发送通知:

 //更新进度
            builder.setProgress((int) l, (int) l1, true);
            //发送通知
            notificationManager.notify(notificationFlag, builder.build());

取消通知:

 
notificationManager.cancel(notificationFlag);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值