I have an Android app that works for all versions starting from Android-8. Now, as of Android-17, there is additional API that I would like to use, however I don’t wont to set target SDK to Android-17, the goal is that devices from Android-17 and newer use the additional API while the older ones will skip using the features from the new API.
The obvious solution would be to use the reflection for new API, however I can not use it since I need to create a new class that extends the class from new Android-17 API and this is not possible (tried with Proxy and InvocationHandler but they work only for interfaces).
Any ideas how to design this? Preferably without creating 2 different APK builds.
Thanks!
Wrap all access to the new APIs with if statements. Android as of 2.0+ will not throw exceptions due to framework classes not found unless you actually try to use one (previously the verifier would check all classes used exist before running the code). Check android.os.Build.VERSION to see what version the phone is using.