Android 5.0 Heads-up Notification (浮动通知) 的创建方法

本来想在谷歌和百度找找看的,最后发现,相关的资料实在太少了,最终在谷歌文档中找到了相关的方法

总结如下:

//获取通知管理器
NotificationManager NotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//创建一个Intent来传递参数
Intent push = new Intent();
push.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
push.setClass(MainActivity.this, MainActivity.class);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(MainActivity.this, 0, push, PendingIntent.FLAG_CANCEL_CURRENT);
//创建通知
Notification.Builder notificationBuilder = new Notification.Builder(MainActivity.this)
	.setSmallIcon(R.drawable.ic_launcher)
	.setPriority(Notification.PRIORITY_HIGH)
	.setCategory(Notification.CATEGORY_MESSAGE)
	.setContentTitle("Sample Notification")
	.setContentText("Heads-Up Notification on Android L or above.")
	.setFullScreenIntent(fullScreenPendingIntent, true);
//显示通知
NotificationManager.notify(1, notificationBuilder.build());

您可能还喜欢...

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据