T
- the interface which managed implementations implementpublic abstract class PlatformSupportManager<T>
extends java.lang.Object
Sometimes the application wants to access advanced functionality exposed by Android APIs that are only available
in later versions of the platform. While Build.VERSION
can be used to determine the device's API level
and alter behavior accordingly, and it is possible to write code that uses both old and new APIs selectively,
such code would fail to load on older devices that do not have the new API methods.
It is necessary to only load classes that use newer APIs than the device may support after the app has checked the API level. This requires reflection, loading one of several implementations based on the API level.
This class manages that process. Subclasses of this class manage access to implementations of a given interface in an API-level-aware way. Subclasses implementation classes by name, and the minimum API level that the implementation is compatible with. They also provide a default implementation.
At runtime an appropriate implementation is then chosen, instantiated and returned from build()
.
Modifier | Constructor and Description |
---|---|
protected |
PlatformSupportManager(java.lang.Class<T> managedInterface,
T defaultImplementation) |
Modifier and Type | Method and Description |
---|---|
protected void |
addImplementationClass(int minVersion,
java.lang.String className) |
T |
build() |