笔记 android发送状态栏消息

编程环境android4.4+eclipse
定义
NotificationManager manager;
NotificationCompat.Builder notifyBuilder;

在onCreate中
/* 实例化NotificationManager以获取系统服务 */
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

使用
notifyBuilder = new NotificationCompat.Builder(this)
                /* 设置small icon */
                .setSmallIcon(R.drawable.ic_launcher)
                /* 设置title */
                .setContentTitle("打卡")
                /* 设置详细文本 */
                .setContentText(item.title).setTicker("足迹消息")
                /* 设置点击后通知消失 */
                .setAutoCancel(true)
                /* 意图 点击跳转到SignActivity */
                .setContentIntent(pendingIntent);
abc_id++;
manager.notify(100 * abc_id, notifyBuilder.build());

setContentIntent(pendingIntent);
意图 可使用也可不使用,使用需定义下
// 点击的意图ACTION是跳转到Intent
Intent resultIntent = new Intent(this, SignActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,
        0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);


修改后
NotificationManager notificationManager;
NotificationCompat.Builder nb;
String svcName = Context.NOTIFICATION_SERVICE;    

notificationManager = (NotificationManager) getSystemService(svcName);
nb = new Builder(this);

使用
nb2.setSmallIcon(R.drawable.ic_launcher).setContentTitle("标题")
                .setWhen(System.currentTimeMillis())
                .setContentText("内容内容内容"+ncc).setAutoCancel(true).setContentInfo("info");
ncc++;
notificationManager.notify(ncc, nb2.build());
    
解释:
状态栏消息
示例
****    标题                        21:12
****    内容内容内容"+ncc                info
****    
星号是图片区域
setSmallIcon           设置图标
setContentTitle        设置示例中的标题部分
setContentText        设置示例中的内容部分
setContentInfo        设置示例中时间下面的info部分
setAutoCancel        设置消息是否可以被点击取消(被单击后自动取消自己)
setWhen                  设置展开的状态栏按时间顺序排序通知




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值