安卓Notification(更新API)

NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(MainActivity.this);
Resources res = MainActivity.this.getResources();
//显示在最上边的小图
builder.setSmallIcon(R.drawable.bird);
//点开后的大图
builder.setLargeIcon(BitmapFactory.decodeResource(res,R.drawable.dolphin));
//短暂显示的提示
builder.setTicker("This is Ticker");
//通知触发时间:即时
builder.setWhen(System.currentTimeMillis());
//点击通知栏后自动消失
builder.setAutoCancel(true);
//标题
builder.setContentTitle("This is the content title");
//内容
builder.setContentText("This is the content text");
//添加点击事件
Intent intent = new Intent(MainActivity.this,AnotherActivity.class);
PendingIntent pi = PendingIntent.getActivity(MainActivity.this,0,intent,
        PendingIntent.FLAG_CANCEL_CURRENT);
builder.setContentIntent(pi);
//获得Notification
Notification notification = builder.build();
//默认声音
notification.defaults = Notification.DEFAULT_SOUND;
//自定义声音
//Uri soundUri = Uri.fromFile(new File("/system/media/audio/notifications/Cleverer.ogg"));
//notification.sound = soundUri;
//自定义震动,数组下表奇数为震动时间(毫秒),偶数为停止时间
long[] vibrates = {0,500,1000,500,1000,500};
notification.vibrate = vibrates;
//灯光颜色,但是华为手机测试灯不会亮
notification.ledARGB = Color.GREEN;
//灯光闪烁时间(毫秒)
notification.ledOnMS = 1000;
notification.ledOffMS = 1000;
//显示灯光
notification.flags = Notification.FLAG_SHOW_LIGHTS;

manager.notify(1,notification);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值