notification新旧用法 notification builder

api 11 版本之前:

//显示通知信息
	protected void showNotification() {
		NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//				Notification notification = new Notification(this,R.drawable.ic_launcher);
		Notification notification = new Notification(R.drawable.ic_launcher,"",System.currentTimeMillis() );
		PendingIntent contentIndent = PendingIntent.getActivity(MainActivity.this, 0, new Intent(MainActivity.this,MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
		notification.setLatestEventInfo(MainActivity.this, "您的BMI值过高", "通知监督人", contentIndent);
		//加i是为了显示多条Notification
		notificationManager.notify(i,notification);
		i++;
	}


api版本之后:

protected void showNotification2() {
		NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
		Builder builder = new Notification.Builder(MainActivity.this);
		PendingIntent contentIndent = PendingIntent.getActivity(MainActivity.this, 0, new Intent(MainActivity.this,MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
		builder . setContentIntent(contentIndent) .setSmallIcon(R.drawable.ic_launcher)//设置状态栏里面的图标(小图标)                     .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.i5))//下拉下拉列表里面的图标(大图标)        .setTicker("this is bitch!") //设置状态栏的显示的信息
	           .setWhen(System.currentTimeMillis())//设置时间发生时间
	           .setAutoCancel(true)//设置可以清除
	           .setContentTitle("This is ContentTitle")//设置下拉列表里的标题
	           .setContentText("this is ContentText");//设置上下文内容
		Notification notification = builder.getNotification();
		//加i是为了显示多条Notification
		notificationManager.notify(i,notification);
	}

但是如果你的minsdk版本是8的话,毕竟这个是大多数,那么只好选择就版本了,虽然ide会提示此方法已删除



完整代码下载地址:http://pan.baidu.com/s/1kUuPq

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值