(可用) Andorid 的通知类 Notification 过时(deprecated),正确用法

对着教程练习 消息通知 功能时

发现

Notification(int icon, CharSequence tickerText, long when)

居然也过时了

显示 deprecated

正确创建 Notification 的方法如下:

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);

猜你喜欢

转载自hwzyyx.iteye.com/blog/2311513