Different Java methods for different API levels

How can you use the method with some versions for different API levels. I think something like this, but I'm not sure

@apilevel("11")
private void getR()
{
...
}

@apilevel("4")
private void getR()
{
...
}

What is the right way to do this? thanks in advance

+5
source share
2 answers

You can use:

Integer.valueOf(android.os.Build.VERSION.SDK);

For reference, you can look here: http://developer.android.com/reference/android/os/Build.VERSION.html#SDK

And for the levels themselves there is a list: http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

+4
source

here you will find very good text on this topic:

http://android-developers.blogspot.com/2010/07/how-to-have-your-cupcake-and-eat-it-too.html

, :

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    Log.i(LOG_TAG, "At least ICS version");
}
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    Log.i(LOG_TAG, "At least HoneyComb version");
}
else {
    Log.i(LOG_TAG, "legacy");
}

const, ICE_CREAM_SANDWICH, Java, , , Android- sdk-s . , , , sdk-s, VFY.

, android :

interface ImplBase {
void myFunc();
};

class ICSImp implements ImplBase {
public void myFunc(){}
}

class HoneyCombImp implements ImplBase {
public void myFunc(){}
}

class LegaceImp implements ImplBase {
public void myFunc(){}
}
+7

All Articles