Android 提示 Notification 通知

/**
 * 创建通知
 * @param tickerText 来通知时的提示内容
 * @param title 通知标题(下拉后显示)
 * @param content 通知内容(下拉后显示)
 * @param drawable 通知图标
 * @param cls 点击后跳转到哪个类
 */
@SuppressWarnings("deprecation")
private void setNotification(String tickerText, String title,String content, int drawable, Class<?> cls) {
	Notification notification = new Notification(drawable, tickerText,System.currentTimeMillis());
	notification.flags |= Notification.FLAG_ONGOING_EVENT;
	notification.flags |= Notification.FLAG_AUTO_CANCEL;
	// 控制提示灯
	notification.ledARGB = 0x00ff00;// 设置通知提醒灯的颜色
	notification.ledOnMS = 300;// 提醒灯亮的时间
	notification.ledOffMS = 3000;// 提醒灯灭的时间
	notification.flags |= Notification.FLAG_SHOW_LIGHTS;// 设置notify调用提示灯
	notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);//设置默认的铃声
    notification.defaults = Notification.DEFAULT_SOUND;//设置开启声音
    notification.defaults = Notification.DEFAULT_LIGHTS;//设置开启指示灯
    notification.defaults = Notification.DEFAULT_VIBRATE;// 设置notify调用震动器需加权限:mission.VIBRATE
	
	Intent intent = new Intent(this, cls);
	intent.setAction(Intent.ACTION_MAIN);
	intent.addCategory(Intent.CATEGORY_LAUNCHER);
	intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
	PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
	notification.setLatestEventInfo(this, title, content, contentIntent);
	notificationManager.notify(0, notification);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值