private void showNotification(Context context){
Intent intent = new Intent(context, MainActivity.class);
NotificationManager manager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification nfication=new Notification(R.mipmap.ic_launcher,"红包马上就开枪啦",System.currentTimeMillis());
nfication.defaults = Notification.DEFAULT_LIGHTS|Notification.DEFAULT_SOUND;
nfication.ledARGB = Color.BLUE;
nfication.ledOnMS =10000;
nfication.ledOffMS=0;
PendingIntent pi=PendingIntent.getActivity(context, 123, intent,PendingIntent.FLAG_UPDATE_CURRENT);
nfication.setLatestEventInfo(context,"红包马上就开枪啦","哈哈", pi);
nfication.flags= Notification.FLAG_SHOW_LIGHTS |Notification.FLAG_ONGOING_EVENT |Notification.FLAG_AUTO_CANCEL;
manager.notify(1234, nfication);
//1234 通知id 比如你想取消掉这个通知需要用到
}
Android 简单创建一条通知
最新推荐文章于 2024-01-10 18:19:11 发布