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());
近期评论