(Available) Andorid's notification class Notification is deprecated, use it correctly

When practicing the message notification function with the tutorial

 

Discover

Notification(int icon, CharSequence tickerText, long when)

 

It's out of date

show deprecated

 

The correct way to create a Notification is as follows:

 

NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

Notification.Builder builder = new Notification.Builder(MainActivity.this);

builder.setContentText("aaaa");
builder.setContentTitle("bbbb");
builder.setSmallIcon(R.drawable.apple);

builder.setWhen(System.currentTimeMillis());

Notification notification = builder.build();

manager.notify(1,notification);

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326792531&siteId=291194637