绵阳做网站的公司,开发板公测的更新频率,南京平面设计培训,外贸行业网站建设公司最近在项目中需要使用消息通知#xff0c;自己把它封装成了一个方法#xff0c;需要的时候方便调用#xff0c;下面对Notification类中的一些常量#xff0c;字段#xff0c;方法简单介绍一下#xff1a;常量#xff1a;DEFAULT_ALL 使用所有默认值#xff0c;比如声… 最近在项目中需要使用消息通知自己把它封装成了一个方法需要的时候方便调用下面对Notification类中的一些常量字段方法简单介绍一下常量DEFAULT_ALL 使用所有默认值比如声音震动闪屏等等DEFAULT_LIGHTS 使用默认闪光提示DEFAULT_SOUNDS 使用默认提示声音DEFAULT_VIBRATE 使用默认手机震动 【说明】加入手机震动一定要在manifest.xml中加入权限uses-permission android:nameandroid.permission.VIBRATE /以上的效果常量可以叠加,即通过notification.defaults DEFAULT_SOUND|DEFAULT_VIBRATE; notification.defaults | DEFAULT_SOUND (最好在真机上测试震动效果模拟器上没有)//设置flag位 FLAG_AUTO_CANCEL 该通知能被状态栏的清除按钮给清除掉FLAG_NO_CLEAR 该通知能被状态栏的清除按钮给清除掉FLAG_ONGOING_EVENT 通知放置在正在运行FLAG_INSISTENT 是否一直进行比如音乐一直播放知道用户响应常用字段contentIntent 设置PendingIntent对象点击时发送该Intentdefaults 添加默认效果flags 设置flag位例如FLAG_NO_CLEAR等icon 设置图标sound 设置声音tickerText 显示在状态栏中的文字when 发送此通知的时间戳/*******************************************分割线************************************************/贴上源代码 private void showNotification(CharSequence Title,CharSequence Text){//获得通知管理器NotificationManager manager (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);//构建一个通知对象(需要传递的参数有三个,分别是图标,标题和 时间)Notification notification new Notification(R.drawable.logo_notify,Title,System.currentTimeMillis());notification.flags Notification.FLAG_AUTO_CANCEL;//点击后自动消失notification.defaults Notification.DEFAULT_SOUND;//声音默认//定义下拉通知栏时要展现的内容信息 Context context getApplicationContext(); //点击该通知后要跳转的ActivityIntent intent new Intent(this,Target.class);BudgetSetting.budgetFlagSetting;PendingIntent pendingIntent PendingIntent.getActivity(AccountAdding.this,0,intent,0); notification.setLatestEventInfo(getApplicationContext(), 通知标题, 通知显示的内容, pendingIntent);notification.setLatestEventInfo(context, Title, Text, pendingIntent);//用mNotificationManager的notify方法通知用户生成标题栏消息通知 manager.notify(1, notification);finish(); } 转载于:https://blog.51cto.com/alany/1590726