Old and New Notification的创建 以及自定义的

 //创建old通知 设置status Icon 和tickerText 
  notification = new Notification(R.drawable.ic_launcher, "我是old通知",
    System.currentTimeMillis());
  
  Intent intent = new Intent(this, OtherActivity.class);
  //点击通知栏中的通知后进行加载Intent并执行intent的action将Activity跳转
  PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
    intent, 0);
  //通知在通知栏中的设置信息
  notification.setLatestEventInfo(this, "hillo!!", "你好!欢迎光临",
    contentIntent);
  //获取通知manager对象
  notifiManager = (NotificationManager) this
    .getSystemService(NOTIFICATION_SERVICE);
  //manager将通知显示 如需要点击后删除通知 需Manager对象调用cancle(通知标识符id) cancleAll()或者Builder.setAutoCancle();
  notifiManager.notify(100, notification);

 

//android4.1后notification

 Intent intent = new Intent(this, OtherActivity.class);
  PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
    intent, 0);
  notifiBuilder = new Notification.Builder(this)
    .setSmallIcon(R.drawable.ic_launcher).setTicker("new通知来了")
    .setContentTitle("hello,我是title")
    .setContentText("这是contentText")
    .setContentIntent(contentIntent)
    // 设置通知的声音,震动,Led灯  
//震动需要添加用户权限 android.permission.VIBRATE
    .setDefaults(Notification.DEFAULT_ALL);
  notification=notifiBuilder.build();
  notifiManager.notify(200,notification);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值