Android创建使用默认布局的通知

创建一个使用默认布局的通知:

NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

Notification notification = new Notification(R.drawable.ic_launcher,"this is ticker text",System.currentTimeMillis());
// 第一个参数用于指定通知图标,第二个参数用于指定通知到来时闪一下显示的文字,第三个显示通知到来的时间

Intent intent = new Intent(this,NotificationActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_CANCEL_CURRENT); // 设置通知点击响应

notification.setLatestEventInfo(this,"this is content title","this is content text",pi);  // 用于指定通知布局显示内容

Uri soundUri = Uri.fromFile(new File("/system/media/audio/ringtones/Basic_tone.ogg"));
notification.sound = sound; // 通知到来时铃声提醒

/**
 * 需要震动权限
 */
long[] vibrates = {0,1000,1000,1000};  // 0,2,4...表示静止时长,1,3,5...表示震动时长
notification.vibrate = vibrates;   // 设置震动提醒(这个数组的意思是,来了同时马上震动1秒,静止一秒,再震动一秒)

/**
 * 用于实现有未读通知时LED灯闪烁
 */
notification.ledARGB = Color.GREEN;  // 一般有红绿蓝可选
notification.ledOnMS = 1000;         // 指定LED灯亮起的时长,以毫秒为单位
notification.ledOffMS = 1000;        // 指定LED灯暗去的时长,以毫秒为单位
notification.flags = Notification.FLAG_SHOW_LIGHTS;   // flags用于指定通知一些行为,其中就有显示LED灯这一项

manager.notify(1,notification);  // 显示通知,每个通知的id(第一个参数)要唯一
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值