最近在项目中需要使用消息通知,自己把它封装成了一个方法,需要的时候方便调用,
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();
//点击该通知后要跳转的Activity
Intent intent = new Intent(this,Target.class);
BudgetSetting.budgetFlag="Setting";
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();
}
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。