android 通知

android中的通知,想必都用过把,来信息的时候会在屏幕的最上面显示,好了废话不说了  先看下效果图把

以上点击按钮会发送一个通知  并且点击通知会进入拨号盘

接下来 看代码把

	//普通通知
	public void send(View view){
		//发送通知
		//通知管理服务
		NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
		
		Notification notification = new Notification(android.R.drawable.ic_media_play//图标
				, " 我是通知",//信息内容
				System.currentTimeMillis());//时间
		//跳转到拨号盘
		Intent intent =  new Intent(Intent.ACTION_DIAL,Uri.parse("tel:1234"));
		
		//延时意图 其实是对intent的一中分装
		PendingIntent contentIntent = PendingIntent.getActivity(this,100,intent,0);
		
		//事件  设置事件监听
		notification.setLatestEventInfo(this,"标题","内容",contentIntent);//PendingIntent 
		
		//解决通知不销毁的方法  设置通知自动消失
		notification.flags = Notification.FLAG_AUTO_CANCEL;
		//添加到管理类中去
		nm.notify(100, notification);
	}

  注释都有  应该都得懂 好了不懂再联系 我把

转载于:https://www.cnblogs.com/Striver-zw/p/4191437.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值