//Notification是系统的服务,所以通过该方式获取NotificationManager对象
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//获得Notification对象
Notification notification = new Notification(R.drawable.ic_launcher,
"滚动部分内容", System.currentTimeMillis());
//点击通知后要做的动作
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:10086"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
intent, 0);
notification.setLatestEventInfo(this, "我是标题", "我是内容", pendingIntent);
//点击后,通知栏的消息会去掉
notification.flags = Notification.FLAG_AUTO_CANCEL;
//发送通知
notificationManager.notify(id, notification);
//ID不同,就能接收多条不同的通知
id++;
下拉通知Notification
最新推荐文章于 2023-08-28 19:12:52 发布