Android 通知栏信息

本文介绍如何在Android中创建自定义的通知栏信息。通过使用PendingIntent和NotificationCompat.Builder,可以实现带有特定图标、标题和文本的通知,并设置点击行为及自动取消等功能。

1

今天讲点简单的哦,再日后补坑,通知栏信息;
用Android的人,都应该知道通知栏是个什么东西,下拉会出来一些设置菜单,
当有新的消息时,就会跑到这里,或者比如云音乐,后台听歌,也会有这么一个通知栏信息;
今天就简单的说一下,以后再完善;

   PendingIntent pendingIntent = PendingIntent.getActivity(this,0,new Intent(this, Photogallery_activity.class),0);   //某个intent

            Notification notification = new NotificationCompat.Builder(this)         //通知对象的创建
                    .setTicker(resources.getString(R.string.new_picture_title))//信息在通知栏滚动的text,就像新短信会在未下拉的状态来滚动信息
                    .setSmallIcon(android.R.drawable.ic_menu_report_image)//图标
                    .setContentTitle(resources.getString(R.string.new_picture_title))//标题
                    .setContentText(resources.getString(R.string.new_picture_text))//文本
                    .setContentIntent(pendingIntent)//点击后启动的intent
                    .setAutoCancel(true)//点击后自动取消,比如云音乐,你点击后,就跳到主页面,不删除通知栏
                    .build();

            NotificationManager notificationManager =(NotificationManager)getSystemService(NOTIFICATION_SERVICE); //创建manager

            notificationManager.notify(0,notification);//发送消息

ok,我们就在通知栏建立了我们自己的信息;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值