Android 提示 Notification 通知

来源:互联网 发布:淘宝网怎么买彩票 编辑:程序博客网 时间:2024/05/17 22:35
/** * 创建通知 * @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.VIBRATEIntent 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);}

0 0
原创粉丝点击