android 创建Notification

// 创建一个NotificationManager的引用
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
// 定义Notification的各种属性
int icon = R.drawable.ic_launcher; // 通知图标
CharSequence tickerText = messageString; // 状态栏显示的通知文本提示
long when = System.currentTimeMillis(); // 通知产生的时间,会在通知信息里显示
// 用上面的属性初始化 Nofification
Notification notification = new NotificationCompat.Builder(context)
.setContentTitle(context.getString(R.string.push_notification_title)).setSmallIcon(icon)
.setContentText(tickerText).setAutoCancel(true).setWhen(when).getNotification();
notification.flags = Notification.FLAG_AUTO_CANCEL;
PendingIntent contentIntent = PendingIntent.getActivity(context, (int)System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.contentIntent = contentIntent;
int i = (int) (Math.random() * 1000);
mNotificationManager.notify(i, notification);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值