Android通知之状态栏通知

状态栏通知:

//状态栏通知
public void stateBar(View view){
	//1.得到通知管理器
	NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
	//2.构建通知
	Notification notification = new Notification(android.R.drawable.star_big_off, "这是top信息", System.currentTimeMillis());
	//3.设置通知的点击事件,可以   打开Activity[PendingIntent.getActivity] 打开服务[PendingIntent.getService] 发送广播[PendingIntent.getBroadcast]
	Intent intent = new Intent();
	intent.setAction(Intent.ACTION_CALL);
	intent.setData(Uri.parse("tel:110"));
	/**
	 * 参数一:上下文环境
	 * 参数二:请求码(随意)
	 * 参数三:由于这里是打开Activity,所以参数三就是意图
	 * 参数四:标志位(写0即可)
	 */
	PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 100, intent, 0);
	//步骤三,上面设置的都是步骤三的参数
	notification.setLatestEventInfo(getApplicationContext(), "通知标题", "通知内容", contentIntent );
	
	notification.flags = Notification.FLAG_AUTO_CANCEL;//将通知从上拉下来点击后,从上拉下来的这个地方就不显示通知了(点击后自动取消)
	notification.sound = Uri.parse("/mnt/sdcard/jiaodizhu.mp3");//设置收到通知后的声音
	
	//4.发送通知
	manager.notify(id++,notification);//第一个参数让他改变的话,就可以在最上边这一栏有多个通知,否则同一种的只显示一个
}


将通知栏拉下来,如果希望点击通知后自动清除通知栏里的通知就设置notification.flags = Notification.FLAG_AUTO_CANCEL;


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值