Reputation: 1965
I would like to use a method that was introduced in Android API 18 but was deprecated in API 21. However, my app must be compatible with devices with API 18 installed.
Is the proper thing to do to simply continue using this deprecated method? Or should I check the version and have two versions of my code, one for API 18 and one for API 21 and later?
Upvotes: 3
Views: 740
Reputation: 2770
From Deprecated Annotation documentation
A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists.
No one says that will be removed but...imho is better to rewrite the code (if possible) and use the new backward compatibility method.
If you cannot do this check on SDK API version manually.
Upvotes: 0
Reputation: 2858
You can use the method that supports in API 18 and though it is deprecated it does not create you any problem. If you still want to put some validation around it then
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2&&android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
// write your code here which should work for version between 18 and 21.
}
else if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP)
{
// write the alternate code for API 21+
}
Upvotes: 2
Reputation: 625
if you're developing for less than Lolypop than you can use it , if you want the new androids use the replacement
https://developer.android.com/reference/android/bluetooth/le/BluetoothLeScanner.html
Upvotes: 0
Reputation: 3282
Use something like:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {}
Upvotes: 0