This API seems to be introduced in API level 26. Since you might be using AppCompatActivity, maybe they have also introduced some backward compatibility for pre 26 SDK.
Moreover, the warning that you are receiving might just be a lint check error.