读书笔记:安卓悬挂式notification,其实跟普通的只有一行代码的区别
Notification.Builder builder = new Notification.Builder(MainActivity.this);
Intent intent = new Intent(MainActivity.this, SecondActivity.class);PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
builder.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pendingIntent)
.setContentText("contenttext")
.setContentTitle("contenttitle")
.setSubText("subtext")
.setAutoCancel(false)
.setFullScreenIntent(pendingIntent, true)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
Notification notification = builder.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);