我发现我在使用通知(notification)时使用了一个已弃用的方法(notification.setLatestEventInfo())。
它建议使用Notification.Builder。
- 我该如何使用它?
当我尝试创建一个新实例时,它告诉我:
Notification.Builder cannot be resolved to a type
我发现我在使用通知(notification)时使用了一个已弃用的方法(notification.setLatestEventInfo())。
它建议使用Notification.Builder。
当我尝试创建一个新实例时,它告诉我:
Notification.Builder cannot be resolved to a type
// This is a working Notification
private static final int NotificID=01;
b= (Button) findViewById(R.id.btn);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Notification notification=new Notification.Builder(MainActivity.this)
.setContentTitle("Notification Title")
.setContentText("Notification Description")
.setSmallIcon(R.mipmap.ic_launcher)
.build();
NotificationManager notificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notification.flags |=Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(NotificID,notification);
}
});
}