Android_Notification通知

添加权限(闪光灯和震动)

	<uses-permission android:name="android.permission.FLASHLIGHT"/>
	<uses-permission android:name="android.permission.VIBRATE"/>

创建

static final int NOTIFICATION_ID = 0x1234;

					//创建一个启动其他Activity的Intent
					Intent intent = new Intent(AddContactActivity.this
						, ContactManageActivity.class);
					PendingIntent pi = PendingIntent.getActivity(AddContactActivity.this
						, 0, intent , 0);
					//创建一个Notification
					Notification notify = new Notification();
					//为Notification设置图标,该图标显示在状态栏
					notify.icon = R.drawable.contact;
					//为Notification设置文本内容,该文本会显示在状态栏
					notify.tickerText = "启动其他Activity的通知";
					//为Notification设置发送时间
					notify.when = System.currentTimeMillis();
					//为Notification设置声音
					notify.defaults = Notification.DEFAULT_SOUND;
					//为Notification设置默认声音、默认振动、默认闪光灯
					notify.defaults = Notification.DEFAULT_ALL;
					//设置事件信息
					notify.setLatestEventInfo(AddContactActivity.this, "普通通知",
						"点击查看", pi);
					//获取系统的NotificationManager服务
					NotificationManager notificationManager = (NotificationManager) 
						getSystemService(NOTIFICATION_SERVICE);
					//发送通知
					notificationManager.notify(NOTIFICATION_ID, notify);

可以自定义

//设置自定义声音
notify.sound = Uri.parse("file:///sdcard/click.mp3");
//设置自定义振动
notify.vibrate = new long [] {O , 50 , 100 , 150};
//设置闪光灯颜色为红色
notify.ledARGB = OxffffOOOO;
//设置闪光灯多少毫秒后熄灭
notify.ledOffMS= 800;
//设置闪光灯多少毫秒后开启
notify.led,OnMS = OxffffOOOO;


清除

//获取系统的NotificationManager 服务
NotificationManager notificationManager = (NotificationManager).getSystemService(NOTIFICATION_SERVICE);
//取消通知
notificationManager.cancel(NOTIFICATION_ID) ;


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值