通知栏
1、通知栏管理者
manager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE)
通知栏相关属性
Notification.Builder builder=new Notification.Builder(this)//设置相关属性
builder.setTicker("新的消息");//消息提醒文字
builder.setPriority(Notification.PRIORITY_DEFAULT);//设置该通知优先级
builder.setsSmallIcon(R.mipmap.ic_launcher);//图标
builder.setWhen(System.currentTimeMillis());//时间
builder.setContentTitle("警告");//通知栏消息标题
builder.setContentText("你有一条消息,请查收");//消息内容
buidler.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));//获取系统铃声
builder.setVibrate(new long[]{0,300,500,700});//震动
builder.setContentIntent(pend);//跳转
builder.setLights(0xff0000ff,300,0);//指示灯
notification=builder.build();
notification.flags=Notification.FLAG_SHOW_LIGHTS;//设置指示灯
//跳转的pend
Intent intent=new Intent(this,MainActivity.class);
PendingIntent pend=PendingIntent.getActivity(this,0,intent,0);
触发器
通知栏相关信息设置好后怎么使用?
比如点击按钮触发只需要一行代码:manager.notify(12,notification);
全部搞定
----------小弟才艺不精,如有纰漏.请各位赐教------

浙公网安备 33010602011771号