2

I'm working around a library that might be embedded in some Android apps. This library uses Android 2.2+ features but does not mean to be something essential to the usage of the target application.

Thus I would like my lib to be optionnaly runned in target apps, only under the conditions that the environment is Android 2.2+. It would not constrain target apps to be compiled and developed for Android 2.2+ devices, e.g target apps would be compiled for Android 1.6 and the import of Android 2.2 libraries would not mess up all the compilation process.

Is there any way to achieve such goals ?

AsTeR
  • 6,543
  • 12
  • 54
  • 91
  • I am also looking for similar option, like if GPS is there use it.. otherwise market will filter apps based on permission. I dont what to have two version of app just for few devices not having capability. – Dileep Jun 23 '11 at 18:13
  • You had this king of feature embedded in Android SDK, you can test the availability of the GPS look here : http://stackoverflow.com/questions/843675/how-do-i-find-out-if-the-gps-of-an-android-device-is-enabled – AsTeR Jun 24 '11 at 06:21

1 Answers1

1

Yes. Build your app for Android 1.6, and check the current SDK version using Build.VERSION.SDK_INT, and use the new functionality using reflection or with dedicated classes that you ONLY access after having verified the SDK version. See this Android blog post for some more information.

EboMike
  • 72,990
  • 14
  • 152
  • 157
  • This is making it painful... forcing you to implement tons of wrapper to have some kind of clean code. – AsTeR Oct 09 '11 at 11:53
  • It's really not that much work. My app is compatible all the way down to 1.5, I have wrappers for 1.6, 2.0, 2.3, 3.0, and it's really easy if you write just one class per Android version with the functions that you need, and one class that tells you the SDK version. – EboMike Oct 10 '11 at 02:09