0

I'm trying to make a library in which I want a method to be used only if it is above a certain API level.

I want the type of error shown here under putStringSet() method

enter image description here

I have used @TargetApi annotation but no success. Developer is still able to use that method without error.

Can you also tell what this type of error is called (in putStringSet() method)

ADM
  • 20,406
  • 11
  • 52
  • 83
H D
  • 77
  • 2
  • 10

1 Answers1

2

I believe you're looking for:

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)

This means that only apps with min sdk of 5.0 (21?) and higher can call this. Others won't be able this method (due to a compile error), so creating and storing an error for that (specially in preferences, of all places) will be pointless.

TooManyEduardos
  • 4,206
  • 7
  • 35
  • 66